Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Help in using XPath for XML having multiple namespace declarat

From: sai@-----------.---------.---
To: NULL
Date: 12/5/2006 12:56:00 AM


Thanks Jones for your help but still i am some queries
1. How to search for elements which belong to default namespace i.e., i want 
to use XML1 model . I had tried by setting the (default and extension) 
namespaces using the IXMLDOMDocument2_setProperty function.
 i.,e for the following xml document, I want to search the following pattern 
"//tuple"
       <?xml version=\"1.0\"?>
       <presence xmlns=\"urn:ietf:params:xml:ns:pidf\"
              xmlns:ex=\"urn:ietf:params:xml:ns:pidf:ex\" >
       <tuple id='xyz'>
       <status><basic>online</basic><ex:ex>busy</ex:ex></status>
       </tuple>
       <tuple id='xyz1'>
       <status><basic>offline</basic></status>
       </tuple>
       </presence>

"Anthony Jones" wrote:

> 
> "sai" <sai@d...> wrote in message
> news:B2EB7545-DFD0-45B9-A79D-8EBABD18951F@m......
> > I have the following xml files.
> >
> > xml1:
> > <?xml version=\"1.0\"?>
> > <presence xmlns=\"urn:ietf:params:xml:ns:pidf\"
> > xmlns:ex=\"urn:ietf:params:xml:ns:pidf:ex\" >
> > <tuple id='xyz'>
> > <status><basic>online</basic><ex:ex>busy</ex:ex></status>
> > </tuple>
> > <tuple id='xyz1'>
> > <status><basic>offline</basic></status>
> > </tuple>
> > </presence>
> > xml2:
> >   <?xml version=\"1.0\"?>
> > <tns:presence xmlns:tns=\"urn:ietf:params:xml:ns:pidf\"
> > xmlns:ex=\"urn:ietf:params:xml:ns:pidf:ex\" >
> > <tuple id='xyz'>
> > <status><basic>online</basic><ex:ex>busy</ex:ex></status>
> > </tuple>
> > <tuple id='xyz1'>
> > <status><basic>offline</basic></status>
> > </tuple>
> > </tns:presence>
> >
> > 1. If I use the "xml1" xml file and execute the following XPath query
> > "//tuple",  I got the response as 0 nodes matched
> > 2: If I use the "xml2" file and execute the same XPath query as above,
> then
> > I got the response as 2 nodes matched.
> >
> > Q1. I do not see any difference in the xml files and both represent same
> > thing but why do i   get differnet response for the same query. Is is
> > mandatory to write namespace declarations similar to that of in xml file
> > "xml2".
> 
> In XML1 you set the default namespace whereas in XML2 you do not.  Since
> tuple has no namepace alias it is part of the default namespace.  However
> XPath searches are not affected by alias declarations in the document hence
> it will search the no-name namespace.    In XML2 tuple belongs to the
> no-name namespace hence the XPath finds it whereas in XML1 tuple belongs to
> the urn:ietf:params:xml:ns:pidf namespace so it doesn't.
> 
> > Q2. How should be the XPath query for searching for "ex:ex" element? If I
> > use the following XPath query, I am getting the response as 0 nodes
> matched.
> 
> In order to search other namespaces using XPath it needs to be informed of
> them.
> This is done using a secondary property on the DOM which is set via the
> setPropery method on the IXMLDOMDocument2 interface.  E.g.-
> 
> oDOM.setProperty("SelectionNamespaces",
> "xmlns:tns='urn:ietf:params:xml:ns:pidf'
> xmlns:ex='urn:ietf:params:xml:ns:pidf:ex'")
> 
> (I don't know C well enough to port this for you)
> 
> Note that eh alias names uses in the above do not need to match the alias
> names used in the document.  Eg. the following XPath will find the tuple
> nodes in XML1:-
> 
> "//tns:tuple"
> 
> Even though tns isn't used in XML1.
> 
> I suspect that you will also need:-
> 
> oDOM.setProperty("SelectionLanguage", "XPath")
> 
> to ensure MSXML3 is actually using XPath.
> 
> 
> 
> 
> 
> >
> > Thanks in advance for your help.
> 
> 
> 


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent