XPath Expression

A

Andreas Baier

Hi,

I want to select all "result" nodes from the following xml-document:

----
<results xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<list id="{678737D9-2BF3-4FF7-A60E-5AA68595C8FB}"/>
<versioning enabled="1"/>
<settings
url="http://racoon/TestDokumente/_layouts/1033/LstSetng.aspx?List={678737D9-
2BF3-4FF7-A60E-5AA68595C8FB}"/>
<result comments="Eine neue Version mit weniger Text" created="2/7/2005
9:19 AM" createdBy="EMEA\baandr" size="24064"
url="http://racoon/TestDokumente/TestDocLibrary/VersioniertesDokument.doc"
version="@6"/>
<result comments="" created="2/7/2005 9:09 AM" createdBy="EMEA\baandr"
size="29184"
url="http://racoon/TestDokumente/_vti_history/1/TestDocLibrary/Versioniertes
Dokument.doc" version="1" />
<result comments="" created="2/7/2005 9:16 AM" createdBy="EMEA\baandr"
size="31744"
url="http://racoon/TestDokumente/_vti_history/2/TestDocLibrary/Versioniertes
Dokument.doc" version="2"/>
<result comments="Eine neue Version" created="2/7/2005 9:18 AM"
createdBy="EMEA\baandr" size="31744"
url="http://racoon/TestDokumente/_vti_history/3/TestDocLibrary/Versioniertes
Dokument.doc" version="3"/>
<result comments="" created="2/7/2005 9:18 AM" createdBy="EMEA\baandr"
size="19968"
url="http://racoon/TestDokumente/_vti_history/4/TestDocLibrary/Versioniertes
Dokument.doc" version="4"/>
<result comments="eine neue version mit mehr Text" created="2/7/2005 9:19
AM" createdBy="EMEA\baandr" size="25088"
url="http://racoon/TestDokumente/_vti_history/5/TestDocLibrary/Versioniertes
Dokument.doc" version="5"/>
</results>
----

The XPath expression "//result" oder "/results/result" does not make the
selection. The only selection while playing
around with xpath I could make was "//@url" or similar (which is not what I
want).

Does someone can give me a hint on what's going wrong here?

regards,

Andreas
 
J

Joris Gillis

I want to select all "result" nodes from the following xml-document:

----
<results xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<list id="{678737D9-2BF3-4FF7-A60E-5AA68595C8FB}"/>
<versioning enabled="1"/>
<settings
url="http://racoon/TestDokumente/_layouts/1033/LstSetng.aspx?List={678737D9-
2BF3-4FF7-A60E-5AA68595C8FB}"/>
<result comments="Eine neue Version mit weniger Text" created="2/7/2005
9:19 AM" createdBy="EMEA\baandr" size="24064"
url="http://racoon/TestDokumente/TestDocLibrary/VersioniertesDokument.doc"
version="@6"/> ....
</results>
----
Hi,

the 'result' elements in this xml document have a namespace, viz 'http://schemas.microsoft.com/sharepoint/soap/', so in orther to match them properly, you have to declare that namespace within your XSL.

e.g.

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:soap="http://schemas.microsoft.com/sharepoint/soap/"
exclude-result-prefixes="soap">

<xsl:eek:utput method="xml" indent="yes"/>

<xsl:template match="/">
<xsl:copy-of select="/soap:results/soap:result"/>
or
<xsl:copy-of select="//soap:result"/>
</xsl:template>

</xsl:stylesheet>

(note that you're not bound to the prefix 'soap', you can name it anything)

regards,
 
A

Andreas Baier

Joris Gillis said:
the 'result' elements in this xml document have a namespace, viz 'http://schemas.microsoft.com/sharepoint/soap/',
so in orther to match them properly, you have to declare that namespace
within your XSL.

Thank you for your help. I do not use Xpath in a transformation, but in
Visual Basic (using constructs like IXmlDomNodes). I'm wondering if there is
a way to select the nodes in xpath only (because I cannot
assign a namespace to my selection)

regards,

Andreas
 
M

Martin Honnen

Andreas said:
within your XSL.

Thank you for your help. I do not use Xpath in a transformation, but in
Visual Basic (using constructs like IXmlDomNodes). I'm wondering if there is
a way to select the nodes in xpath only (because I cannot
assign a namespace to my selection)

If you are using MSXML from MS then you should use
XmlDocument.setProperty("SelectionLanguage", "XPath")
XmlDocument.setProperty("SelectionNamespaces",
"xmlns:soap='http://schemas.microsoft.com/sharepoint/soap/')
XmlDocument.selectNodes("//soap:result")
that is before you call selectNodes you bind a prefix to the namespace
you need to match. That is the proper way to work with namespaces and
MSXML and its selectNodes/selectSingleNode methods.
Besides that you could try
XmlDocument.selectNodes("//*[local-name() = 'result' and
namespaceURI() = 'http://schemas.microsoft.com/sharepoint/soap/']")
but that is cumbersome and inefficient.
 
A

Andreas Baier

If you are using MSXML from MS then you should use
XmlDocument.setProperty("SelectionLanguage", "XPath")
XmlDocument.setProperty("SelectionNamespaces",
"xmlns:soap='http://schemas.microsoft.com/sharepoint/soap/')
XmlDocument.selectNodes("//soap:result")

Thank you very much - that was the missing hint :) My other approach
would have been using XSLT (assigning a prefix for the namespace) and
converting it back to IXMLDOM...
But your approach is much more better :)

regards,

Andreas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top