XPath Expression

Discussion in 'XML' started by Andreas Baier, Feb 8, 2005.

  1. 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
     
    Andreas Baier, Feb 8, 2005
    #1
    1. Advertising

  2. Andreas Baier

    Joris Gillis Guest

    Tempore 09:52:53, die Tuesday 08 February 2005 AD, hinc in foro {comp.text.xml} scripsit Andreas Baier <>:


    > 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,
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Gaudiam omnibus traderat W3C, nec vana fides
     
    Joris Gillis, Feb 8, 2005
    #2
    1. Advertising

  3. "Joris Gillis" <> 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
     
    Andreas Baier, Feb 8, 2005
    #3
  4. Andreas Baier wrote:

    > "Joris Gillis" <> 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/
     
    Martin Honnen, Feb 8, 2005
    #4
  5. "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
     
    Andreas Baier, Feb 8, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    2,028
    jan V
    Jul 29, 2005
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,522
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Anna
    Replies:
    0
    Views:
    572
  4. goog
    Replies:
    0
    Views:
    534
  5. GIMME
    Replies:
    3
    Views:
    12,048
    vforvikash
    Dec 29, 2008
Loading...

Share This Page