473,396 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

XPath Expression

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
4 3932
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
"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


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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: inquirydog | last post by:
Hi- One frusterating thing for me with xsl is that I don't know how to make xslt throw some sort of exception when a value-of path does not exist. For instance, suppose I have the following...
3
by: gimme_this_gimme_that | last post by:
I once downloaded a shareware program that allowed you to open an xml file, click on a text or an attribute, an then see the xpath expression that would fetch that data. The program didn't...
7
by: steve bull | last post by:
I have the following code snippet to read the colorRange attributes for the colorRangeSwatch in the xml file listed below. string expr = "/swatches/colorRangeSwatch/colorRange";...
2
by: ree32 | last post by:
When I import an xml document in Visual studio and Genereate as schema from it, and create a dataset from it, it adds this line into to the root element of my xml file -...
5
by: laks | last post by:
Hi I have the following xsl stmt. <xsl:for-each select="JOB_POSTINGS/JOB_POSTING \"> <xsl:sort select="JOB_TITLE" order="ascending"/> This works fine when I use it. But when using multiple...
5
by: David Thielen | last post by:
Hi; I set up my xml as follows: XmlDocument xml = new XmlDocument(); xml.Load(File.Open("data.xml", FileMode.Open, FileAccess.Read)); XmlNamespaceManager context = new...
6
by: Chua Wen Ching | last post by:
Hi there, I had this xml file with me (not yet consider implementing xml namespaces yet). <?xml version='1.0'?> <Object> <Windows> <EID>1</EID> <EDesc>Error 1</EDesc> </Windows>
4
by: syed.akhlaq | last post by:
Hi, Does anyone know how can I validate XPath expressions using xsd schema? Thanks
2
by: arunairs | last post by:
Hi, Is there a way of validating and XPath? In this case , I am accepting an XPath from the user and I need to validate the XPath syntax. Is there a regular expression available that anyone can...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.