Ingoring xmlns attribute with XQuery
Added by Anonymous over 17 years ago
Legacy ID: #4288577 Legacy Poster: Christopher Schmitz (the_schmitz)
Hi There, I have an xml file that begins like this: <?xml version="1.0" encoding="UTF-8"?> <Signature xmlns="http://www.someplace.org/sig" 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(); config.setXMLVersion(Configuration.XML11); 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")))); exp.run(dynamicContext, new StreamResult(new File("C:/result.html")), null); Thanks in Advance, Chris
Replies (2)
RE: Ingoring xmlns attribute with XQuery - Added by Anonymous over 17 years ago
Legacy ID: #4288838 Legacy Poster: Michael Kay (mhkay)
XQuery coding questions (that have nothing specifically to do with the Saxon implementation) are probably best posted on the XQuery Talk list at x-query.com. 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 "http://www.someplace.org/sig"; in the query prolog. Note however that this will also affect any unprefixed element names in element constructors.
RE: Ingoring xmlns attribute with XQuery - Added by Anonymous over 17 years ago
Legacy ID: #4288880 Legacy Poster: Christopher Schmitz (the_schmitz)
Michael, Thanks the declare works! Also, thanks for pointing out x-query.com, I'm heading over there now,.. Chris
Please register to reply