same line number related???

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

same line number related???

RamKumarDinesh Thillai

  why this is not giving out put? 

Configuration config = new Configuration();
        config.setLineNumbering(true);
        XPathEvaluator xpath = new net.sf.saxon.xpath.XPathEvaluator(config);
        NodeInfo contextNode = net.sf.saxon.event.Builder.build(new StreamSource((new File(xmlFileToLoad))), null, config);
       
        List list = xpath.evaluate("//pubname");
        for (int i=0; i<list.size(); i++) {
            NodeInfo element = (NodeInfo)list;
            System.out.println("Element " + element.getDisplayName() + " at line " + element.getLineNumber());
        }

it returns exception like

net.sf.saxon.trans.DynamicError: Finding root of tree: the context item is undefined
; Line#: 1; Column#: -1
net.sf.saxon.trans.DynamicError: Finding root of tree: the context item is undefined
        at net.sf.saxon.expr.ComputedExpression.dynamicError(ComputedExpression.java:591)
        at net.sf.saxon.expr.RootExpression.getNode(RootExpression.java:76)
        at net.sf.saxon.expr.SingleNodeExpression.iterate(SingleNodeExpression.java:112)
        at net.sf.saxon.expr.PathExpression.iterate(PathExpression.java:754)
        at net.sf.saxon.xpath.XPathEvaluator.evaluate(XPathEvaluator.java:206)
        at testforxpath.DOMSaxon_EvalXPath.evalXPath(DOMSaxon_EvalXPath.java:106)
        at testforxpath.DOMSaxon_EvalXPath.main(DOMSaxon_EvalXPath.java:69)

can i know the reason for this.and what actually this NodeInfo contextNode have?



Reply | Threaded
Open this post in threaded view
|

RE: same line number related???

Michael Kay
You have built a source document but you haven't told the XPathEvaluator of its existence. You need to do this using the setSource() method, or alternatively one of the evaluate methods that takes a context node as an extra argument.
 
Michael Kay
http://www.saxonica.com/


From: [hidden email] [mailto:[hidden email]] On Behalf Of RamKumarDinesh Thillai
Sent: 14 October 2005 12:10
To: [hidden email]
Subject: [saxon] same line number related???

  why this is not giving out put? 

Configuration config = new Configuration();
        config.setLineNumbering(true);
        XPathEvaluator xpath = new net.sf.saxon.xpath.XPathEvaluator(config);
        NodeInfo contextNode = net.sf.saxon.event.Builder.build(new StreamSource((new File(xmlFileToLoad))), null, config);
       
        List list = xpath.evaluate("//pubname");
        for (int i=0; i<list.size(); i++) {
            NodeInfo element = (NodeInfo)list;
            System.out.println("Element " + element.getDisplayName() + " at line " + element.getLineNumber());
        }

it returns exception like

net.sf.saxon.trans.DynamicError: Finding root of tree: the context item is undefined
; Line#: 1; Column#: -1
net.sf.saxon.trans.DynamicError: Finding root of tree: the context item is undefined
        at net.sf.saxon.expr.ComputedExpression.dynamicError(ComputedExpression.java:591)
        at net.sf.saxon.expr.RootExpression.getNode(RootExpression.java:76)
        at net.sf.saxon.expr.SingleNodeExpression.iterate(SingleNodeExpression.java:112)
        at net.sf.saxon.expr.PathExpression.iterate(PathExpression.java:754)
        at net.sf.saxon.xpath.XPathEvaluator.evaluate(XPathEvaluator.java:206)
        at testforxpath.DOMSaxon_EvalXPath.evalXPath(DOMSaxon_EvalXPath.java:106)
        at testforxpath.DOMSaxon_EvalXPath.main(DOMSaxon_EvalXPath.java:69)

can i know the reason for this.and what actually this NodeInfo contextNode have?



Reply | Threaded
Open this post in threaded view
|

Re: RE: same line number related???

RamKumarDinesh Thillai
In reply to this post by RamKumarDinesh Thillai

 
yeah it worked i can only get one node result only. can i get the node say a table element using xpath and iterating it for its child node some thing like this.

Configuration config = new Configuration();
      config.setLineNumbering(true);
      XPathEvaluator xpath = new net.sf.saxon.xpath.XPathEvaluator(config);

      NodeInfo contextNode = net.sf.saxon.event.Builder.build(new StreamSource((new File("d:\\eqcschema\\test.xml"))), null, config);
      xpath.setSource(contextNode);
      List list =xpath.evaluate("//table");
      for (int i = 0; i < list.size(); i++) {
          NodeInfo element = (NodeInfo) list.get(i);
          xpath.setContextNode(element);
          System.out.println("Element " + element.getDisplayName()+ " at line " + element.getLineNumber());
          List list1 =xpath.evaluate("//row");
          for (int i1 = 0; i1 < list1.size(); i1++) {
          NodeInfo element1 = (NodeInfo) list1.get(i1);
          System.out.println("Element " + element1.getDisplayName()+ " at line " + element1.getLineNumber());
          }
           
      }

if the document is like
<root>
  <table id="t1">
    <row/>
    <row/>
    <row/>
    <row/>
  </table>
  <table id="t2">
    <row/>
    <row/>
    <row/>
    <row/>
  </table>
</root>

basically after i enter into particular data i need to work out with that table rows.
i did using javax.xml.xpath

                XPath xpath =XPathFactory.newInstance().newXPath();
               
                for(int t=0;t<tableNode.getLength();t++){
                Node table=tableNode.item(t);
                /*--------------------------------------------------------------------------------------------*/
                String expression = "./@id";
                //Get The Id Value Of The Table.
                Node idval = (Node)xpath.evaluate(expression, table, XPathConstants.NODE);
                System.out.println("The Table having \"id\" Value : "+idval.getNodeValue());
                // Number Of Rows In A Table
                expression = "count(.//row)";
                Double noofrow = (Double)xpath.evaluate(expression, table, XPathConstants.NUMBER);
                int rowtot=noofrow.intValue();
              // System.out.println("Number Of rows Found "+rowtot+" in the table having id as "+idval.getNodeValue());
               
                // Number Of Entry in A Table
                expression = "count(.//row/entry)";
                Double noofentry = (Double)xpath.evaluate(expression, table, XPathConstants.NUMBER);
                int enttot=noofentry.intValue();

}

i get the result correctly wht i require is it possible here.?
On Fri, 14 Oct 2005 Michael Kay wrote :
>You have built a source document but you haven't told the XPathEvaluator of
>its existence. You need to do this using the setSource() method, or
>alternatively one of the evaluate methods that takes a context node as an
>extra argument.
>
>Michael Kay
>http://www.saxonica.com/
>
>
>  _____
>
> From: [hidden email]
>[mailto:[hidden email]] On Behalf Of RamKumarDinesh
>Thillai
>Sent: 14 October 2005 12:10
>To: [hidden email]
>Subject: [saxon] same line number related???
>
>
>
>  why this is not giving out put?
>
>Configuration config = new Configuration();
>        config.setLineNumbering(true);
>        XPathEvaluator xpath = new
>net.sf.saxon.xpath.XPathEvaluator(config);
>        NodeInfo contextNode = net.sf.saxon.event.Builder.build(new
>StreamSource((new File(xmlFileToLoad))), null, config);
>
>        List list = xpath.evaluate("//pubname");
>        for (int i=0; i<list.size(); i++) {
>            NodeInfo element = (NodeInfo)list;
>            System.out.println("Element " + element.getDisplayName() + " at
>line " + element.getLineNumber());
>        }
>
>it returns exception like
>
>net.sf.saxon.trans.DynamicError: Finding root of tree: the context item is
>undefined
>; Line#: 1; Column#: -1
>net.sf.saxon.trans.DynamicError: Finding root of tree: the context item is
>undefined
>        at
>net.sf.saxon.expr.ComputedExpression.dynamicError(ComputedExpression.java:59
>1)
>        at net.sf.saxon.expr.RootExpression.getNode(RootExpression.java:76)
>        at
>net.sf.saxon.expr.SingleNodeExpression.iterate(SingleNodeExpression.java:112
>)
>        at net.sf.saxon.expr.PathExpression.iterate(PathExpression.java:754)
>        at
>net.sf.saxon.xpath.XPathEvaluator.evaluate(XPathEvaluator.java:206)
>        at
>testforxpath.DOMSaxon_EvalXPath.evalXPath(DOMSaxon_EvalXPath.java:106)
>        at testforxpath.DOMSaxon_EvalXPath.main(DOMSaxon_EvalXPath.java:69)
>
>can i know the reason for this.and what actually this NodeInfo contextNode
>have?
>
>
>
>
>
><http://adworks.rediff.com/cgi-bin/AdWorks/sigclick.cgi/www.rediff.com/signa
>ture-home.htm/1507191490@Middle5?PARTNER=3>
>



Reply | Threaded
Open this post in threaded view
|

Re: Re: RE: same line number related???

RamKumarDinesh Thillai
In reply to this post by RamKumarDinesh Thillai

  yeah michael it is working fine. since i am started working in saxon, i took time to get more familiarized with the same. any way. thnx for ur help. if i have any trouble i just ask u.


On Sat, 15 Oct 2005 RamKumarDinesh Thillai wrote :
>
>yeah it worked i can only get one node result only. can i get the node say a table element using xpath and iterating it for its child node some thing like this.
>
>Configuration config = new Configuration();
>        config.setLineNumbering(true);
>        XPathEvaluator xpath = new net.sf.saxon.xpath.XPathEvaluator(config);
>
>        NodeInfo contextNode = net.sf.saxon.event.Builder.build(new StreamSource((new File("d:\\eqcschema\\test.xml"))), null, config);
>        xpath.setSource(contextNode);
>        List list =xpath.evaluate("//table");
>        for (int i = 0; i < list.size(); i++) {
>            NodeInfo element = (NodeInfo) list.get(i);
>            xpath.setContextNode(element);
>            System.out.println("Element " + element.getDisplayName()+ " at line " + element.getLineNumber());
>            List list1 =xpath.evaluate("//row");
>            for (int i1 = 0; i1 < list1.size(); i1++) {
>            NodeInfo element1 = (NodeInfo) list1.get(i1);
>            System.out.println("Element " + element1.getDisplayName()+ " at line " + element1.getLineNumber());
>            }
>
>        }
>
>if the document is like
><root>
>  <table id="t1">
>      <row/>
>      <row/>
>      <row/>
>      <row/>
>  </table>
>  <table id="t2">
>      <row/>
>      <row/>
>      <row/>
>      <row/>
>  </table>
></root>
>
>basically after i enter into particular data i need to work out with that table rows.
>i did using javax.xml.xpath
>
>                XPath xpath =XPathFactory.newInstance().newXPath();
>
>                for(int t=0;t<tableNode.getLength();t++){
>                Node table=tableNode.item(t);
>                /*--------------------------------------------------------------------------------------------*/
>                String expression = "./@id";
>                //Get The Id Value Of The Table.
>                Node idval = (Node)xpath.evaluate(expression, table, XPathConstants.NODE);
>                System.out.println("The Table having \"id\" Value : "+idval.getNodeValue());
>                  // Number Of Rows In A Table
>                expression = "count(.//row)";
>                Double noofrow = (Double)xpath.evaluate(expression, table, XPathConstants.NUMBER);
>                int rowtot=noofrow.intValue();
>                // System.out.println("Number Of rows Found "+rowtot+" in the table having id as "+idval.getNodeValue());
>
>                // Number Of Entry in A Table
>                expression = "count(.//row/entry)";
>                Double noofentry = (Double)xpath.evaluate(expression, table, XPathConstants.NUMBER);
>                int enttot=noofentry.intValue();
>
>}
>
>i get the result correctly wht i require is it possible here.?
>On Fri, 14 Oct 2005 Michael Kay wrote :
> >You have built a source document but you haven't told the XPathEvaluator of
> >its existence. You need to do this using the setSource() method, or
> >alternatively one of the evaluate methods that takes a context node as an
> >extra argument.
> >
> >Michael Kay
> >http://www.saxonica.com/
> >
> >
> >  _____
> >
> > From: [hidden email]
> >[mailto:[hidden email]] On Behalf Of RamKumarDinesh
> >Thillai
> >Sent: 14 October 2005 12:10
> >To: [hidden email]
> >Subject: [saxon] same line number related???
> >
> >
> >
> >  why this is not giving out put?
> >
> >Configuration config = new Configuration();
> >        config.setLineNumbering(true);
> >        XPathEvaluator xpath = new
> >net.sf.saxon.xpath.XPathEvaluator(config);
> >        NodeInfo contextNode = net.sf.saxon.event.Builder.build(new
> >StreamSource((new File(xmlFileToLoad))), null, config);
> >
> >        List list = xpath.evaluate("//pubname");
> >        for (int i=0; i<list.size(); i++) {
> >            NodeInfo element = (NodeInfo)list;
> >            System.out.println("Element " + element.getDisplayName() + " at
> >line " + element.getLineNumber());
> >        }
> >
> >it returns exception like
> >
> >net.sf.saxon.trans.DynamicError: Finding root of tree: the context item is
> >undefined
> >; Line#: 1; Column#: -1
> >net.sf.saxon.trans.DynamicError: Finding root of tree: the context item is
> >undefined
> >        at
> >net.sf.saxon.expr.ComputedExpression.dynamicError(ComputedExpression.java:59
> >1)
> >        at net.sf.saxon.expr.RootExpression.getNode(RootExpression.java:76)
> >        at
> >net.sf.saxon.expr.SingleNodeExpression.iterate(SingleNodeExpression.java:112
> >)
> >        at net.sf.saxon.expr.PathExpression.iterate(PathExpression.java:754)
> >        at
> >net.sf.saxon.xpath.XPathEvaluator.evaluate(XPathEvaluator.java:206)
> >        at
> >testforxpath.DOMSaxon_EvalXPath.evalXPath(DOMSaxon_EvalXPath.java:106)
> >        at testforxpath.DOMSaxon_EvalXPath.main(DOMSaxon_EvalXPath.java:69)
> >
> >can i know the reason for this.and what actually this NodeInfo contextNode
> >have?
> >
> >
> >
> >
> >
> ><http://adworks.rediff.com/cgi-bin/AdWorks/sigclick.cgi/www.rediff.com/signa
> >ture-home.htm/1507191490@Middle5?PARTNER=3>
> >