Ingoring xmlns attribute with XQuery

  • Christopher Schmitz

    Hi There,
    I have an xml file that begins like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <Signature xmlns="" isClass="true">
    <Header>my header</Header>
    <Version Number="1.1" Date="2007.04.30"/>

    I've created a simple XQuery to return the Header information, which works only if the xmlns attribute DOESN'T exist in the Signature element.  So I was wondering if there is a way I can have saxon ignore the xmlns attribute and continue with the query?  Any help is greatly appreciated!
    Here's the code that I use to create and execute my query:

    Configuration config = new Configuration();

    StaticQueryContext sqc = new StaticQueryContext(config);

    XQueryExpression exp = sqc.compileQuery(" let $doc := . " +
    " for $v in $doc//Signature " +
    " return $v/Header");
    DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
    dynamicContext.setContextItem(config.buildDocument(new StreamSource(new File("C:/signature.xml"))));, new StreamResult(new File("C:/result.html")), null);

    Thanks in Advance,
    • Christopher Schmitz

      Thanks the declare works!

      Also, thanks for pointing out, I'm heading over there now,..


    • Michael Kay

      Michael Kay - 2007-05-01

      XQuery coding questions (that have nothing specifically to do with the Saxon implementation) are probably best posted on the XQuery Talk list at

      You can't ignore the namespace in which your source elements appear - the namespace is an intrinsic part of the element name of every element in your document. What you can do is to include

      declare default element namespace "";

      in the query prolog.

      Note however that this will also affect any unprefixed element names in element constructors.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks