I can't see what you're doing wrong, but when I run this code:
 
    public static void main(String[] args) throws Exception {
        Configuration config = new Configuration();
        config.setLineNumbering(true);
        XPathEvaluator xpath = new net.sf.saxon.xpath.XPathEvaluator(config);
        NodeInfo doca = xpath.setSource(new StreamSource((new File(args[0]))));
        List list = xpath.evaluate("//*");
        for (int i=0; i<list.size(); i++) {
            NodeInfo element = (NodeInfo)list.get(i);
            System.out.println("Element " + element.getDisplayName() + " at line " + element.getLineNumber());
        }
    }
 
with the standard books.xml file supplied as args[0], the output looks like this:
 
Element BOOKLIST at line 4
Element BOOKS at line 5
Element ITEM at line 6
Element TITLE at line 7
Element AUTHOR at line 8
Element PUBLISHER at line 9
Element PUB-DATE at line 10....

The only thing I can think of is that you're using an XML parser that doesn't report line numbers; but I've
never come across that problem (and Saxon relies on the line numbers for reporting errors in stylesheets,
so it would be very noticeable).
 
Could you confirm you are using Saxon 8.5.1 - do
 
    System.out.println("Saxon Version " + net.sf.saxon.Version.getProductTitle());
 
Perhaps you could send me a complete standalone program that demonstrates the problem, with full details of the environment in which you are running it.
 
By the way, my name is Michael - capital M, and the "a" comes before the "e". And it's helpful to use a subject line that enables people to recognize whether the thread is relevant to them.
 
Michael Kay
http://www.saxonica.com/


From: saxon-help-admin@lists.sourceforge.net [mailto:saxon-help-admin@lists.sourceforge.net] On Behalf Of RamKumarDinesh Thillai
Sent: 08 October 2005 05:28
To: saxon-help@lists.sourceforge.net
Subject: Re: Re: [saxon] ok micheal

  i tried this code for my testing purpose
            Configuration config = new Configuration();
            config.setLineNumbering(true);
            XPathEvaluator xpath = new XPathEvaluator(config);
            NodeInfo doca = xpath.setSource(new StreamSource((new File(xmlFileToLoad))));
            List list = xpath.evaluate("//*");
            for (int i=0; i<list.size(); i++) {
                NodeInfo element = (NodeInfo)list.get(i);
                if((element.getDisplayName().equals("emph")) && !element.hasChildNodes())
                System.out.println("Element " + element.getDisplayName() + " at line " + element.getLineNumber());
            }

here i am checking for any empty emph element is there.

it is there but the result i got through this is
"Element emph at line -1"

I hope u got my problem.dont you?


On Sat, 08 Oct 2005 RamKumarDinesh Thillai wrote :
>i used this code,
>   Configuration config = new Configuration();
>            config.setLineNumbering(true);
>
>
>            XPathEvaluator xpath = new XPathEvaluator(config);
>            NodeInfo doca = xpath.setSource(new StreamSource((new File(xmlFileToLoad))));
>            // String expression = "//artfront/artinfo/pubinfo/pubname";
>            List list = xpath.evaluate("//*");
>            for (int i=0; i<list.size(); i++) {
>                NodeInfo element = (NodeInfo)list.get(i);
>                System.out.println("Element " + element.getDisplayName() + " at line " + element.getLineNumber());
>            }
>
>it reads all the node and gives line number as -1 to all? :(:(
>i dont know where i am going wrong..
>
>On Sat, 08 Oct 2005 RamKumarDinesh Thillai wrote :
> >
> >which one to use for parsing a document?
> >i used this
> >System.setProperty("javax.xml.parsers.DocumentBuilderFactory","net.sf.saxon.dom.DocumentBuilderFactoryImpl");
> >
> >but still it has the problem.is there anyother way to use dom so that it can be done to get the line number?