The Javadoc for XPathCompiler.declareNamespace() explains that to set the default namespace you set the first argument to a zero-length string:
 
http://www.saxonica.com/documentation/javadoc/net/sf/saxon/s9api/XPathCompiler.html#declareNamespace(java.lang.String,%20java.lang.String)
 
The class QName has various constructors, the most useful is the 2-argument constructor where the first argument is the namespace URI and the second is the local name. You can also include a prefix if you want, but it makes no difference when you are using the QName for matching.
 
http://www.saxonica.com/documentation/javadoc/index.html?net/sf/saxon/s9api/QName.html
 
So you want newQName("http://www.xbrl.org/2003/instance", "context")
 

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay

 


From: Geet Gangwar [mailto:geetgangwar@gmail.com]
Sent: 19 October 2009 13:49
To: Mailing list for the SAXON XSLT and XQuery processor
Subject: Re: [saxon] help for getting line number

Thanks Michael for your quick answer,

I am trying to query the xml files (xbrl documents) with namespaces, I tried sample code given in saxon library in S9APIExamples.java class with test case XPathA. I have declare the namespace but not getting how to set defaultNamespace and when I run the code its gives me error in Qname class "java.lang.IllegalArgumentException: Local name contains a colon". I have mentioned the sample code. plz tell me where I am wrong.

private static class XPathA implements S9APIExamples.Test {
        public String name() {
            return "XPathA";
        }

        public boolean needsSaxonEE() {
            return false;
        }

        public void run() throws SaxonApiException {
            try {
                Processor proc = new Processor(false);
                XPathCompiler xpath = proc.newXPathCompiler();
                
                //xpath.declareNamespace("saxon", "http://saxon.sf.net/"); // not actually used, just for demonstration
   
                // xpath.declareNamespace("xmlns","http://www.w3.org/1999/xlink");
                xpath.declareNamespace("xbrli", "http://www.xbrl.org/2003/instance");
                xpath.declareNamespace("bvf", "http://www.biovail.com/2008-12-31");
                xpath.declareNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
                xpath.declareNamespace("xlink", "http://www.w3.org/1999/xlink");
            
                //xpath.setDefaultElementTypeNamespace("http://www.xbrl.org/2003/linkbase");
                //xpath.setDefaultElementTypeNamespace("http://www.w3.org/2001/XMLSchema");
                
                DocumentBuilder builder = proc.newDocumentBuilder();
                builder.setLineNumbering(true);
                builder.setWhitespaceStrippingPolicy(WhitespaceStrippingPolicy.ALL);
                XdmNode booksDoc = builder.build(new File("D:/XBRL/Testing/files/biovail/bvf-20081231.xml"));
   
                // find all the ITEM elements, and for each one display the TITLE
                // child
   
                XPathSelector selector = xpath.compile("//xbrli:xbrl").load();
                selector.setContextItem(booksDoc);
                QName titleName = new QName("xbrli:context");
                for (XdmItem item : selector) {
                    XdmNode title = getChild((XdmNode) item, titleName);
                    System.out.println(title.getNodeName() + "(" + title.getLineNumber() + "): " + title.getStringValue());
                }
            }
            catch(Exception e){
                e.printStackTrace();
            }
        }

        // Helper method to get the first child of an element having a given
        // name.
        // If there is no child with the given name it returns null

        private static XdmNode getChild(XdmNode parent, QName childName) {
            XdmSequenceIterator iter = parent.axisIterator(Axis.CHILD, childName);
            if (iter.hasNext()) {
                return (XdmNode) iter.next();
            }
            else {
                return null;
            }
        }
    }

Thanks in advance.

Regards
Geet.

On Mon, Oct 19, 2009 at 4:21 PM, Michael Kay <mike@saxonica.com> wrote:
Make sure that line numbering is enabled when you build the source document (e.g. by using -l option on the command line). Then use the saxon:line-number() extension function.
 

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay



From: Geet Gangwar [mailto:geetgangwar@gmail.com]
Sent: 19 October 2009 11:33
To: saxon-help@lists.sourceforge.net
Subject: [saxon] help for getting line number

Hi,

Can anybody please tell me how I can retrieve line number of nodes which I get through XQuery.

Thanks in advance

Regards
Geet.

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/saxon-help