By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,221 Members | 1,075 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,221 IT Pros & Developers. It's quick & easy.

XPath Expression

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Tempore 09:52:53, die Tuesday 08 February 2005 AD, hinc in foro {comp.text.xml} scripsit Andreas Baier <an***********@web.de>:

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:output 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,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Gaudiam omnibus traderat W3C, nec vana fides
Jul 20 '05 #2

P: n/a
"Joris Gillis" <ro**@pandora.be> wrote
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
Jul 20 '05 #3

P: n/a


Andreas Baier wrote:
"Joris Gillis" <ro**@pandora.be> wrote

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)


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.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #4

P: n/a
"Martin Honnen" wrote
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
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.