473,385 Members | 1,402 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,385 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 3929
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.