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 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", ""); // not actually used, just for demonstration
                // xpath.declareNamespace("xmlns","");
                xpath.declareNamespace("xbrli", "");
                xpath.declareNamespace("bvf", "");
                xpath.declareNamespace("xsi", "");
                xpath.declareNamespace("xlink", "");
                DocumentBuilder builder = proc.newDocumentBuilder();
                XdmNode booksDoc = 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();
                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){

        // 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);
            else {
                return null;

Thanks in advance.


On Mon, Oct 19, 2009 at 4:21 PM, Michael Kay <> 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.


Michael Kay

From: Geet Gangwar []
Sent: 19 October 2009 11:33
Subject: [saxon] help for getting line number


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

Thanks in advance


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!
saxon-help mailing list archived at