XPath Convert Node to String

Discussion in 'XML' started by sshahin@gmail.com, Oct 24, 2005.

  1. Guest

    Is there a way to Convert a Node to a String using XPath 1.0? For
    example, consider the following xml doc:

    <?xml version="1.0" encoding="UTF-8"?>
    <FaultTo xmlns="http://blah.org"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Address>http://www.altova.com</Address>

    <ReferenceProperties>

    <fabrikam:CustomerKey1 xmlns:fabrikam="http://blah.com">3333
    <fabrikam:type>TYPE4</fabrikam:type>
    </fabrikam:CustomerKey1>

    <fabrikam:CustomerKey2
    xmlns:fabrikam="http://blah.com">4444</fabrikam:CustomerKey2>

    <fabrikam:CustomerKey3
    xmlns:fabrikam="http://blah.com">6666</fabrikam:CustomerKey3>

    </ReferenceProperties>

    <ServiceName PortName="NCName">q:name</ServiceName>
    </FaultTo>

    I want to be able to extract and return everything contained within
    <ReferenceProperties> as a string using xpath 1.0 (I do not wish to use
    CDATA or any workarounds like this; basically the XML should be left
    untouched with no modifications).
    , Oct 24, 2005
    #1
    1. Advertising

  2. wrote:

    > Is there a way to Convert a Node to a String using XPath 1.0?


    Yes, you can certainly do
    string(nodeset[1])
    but that gives you what XPath 1.0 defines as the string value of that
    node (see <http://www.w3.org/TR/xpath#function-string> and
    <http://www.w3.org/TR/xpath#element-nodes>) while you seem to want to
    serialize the contents to get back the XML markup of the contents.
    There is no function in XPath 1.0 to serialize nodes.



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Oct 24, 2005
    #2
    1. Advertising

  3. Guest

    This is not what I am looking for. I am looking to return the
    following:

    <fabrikam:CustomerKey1 xmlns:fabrikam="http://blah.com">3333
    <fabrikam:type>TYPE4</fabrikam:type>
    </fabrikam:CustomerKey1>

    <fabrikam:CustomerKey2
    xmlns:fabrikam="http://blah.com">4444</fabrikam:CustomerKey2>
    <fabrikam:CustomerKey3
    xmlns:fabrikam="http://blah.com">6666</fabrikam:CustomerKey3>

    I seem to agree with you that Xpath may not have a built-in function
    for extracting an XML fragment as a string. If there is anyone else
    out there who can provide input, I would greatly appreciat it.
    , Oct 24, 2005
    #3
  4. <> wrote in message
    news:...
    > This is not what I am looking for. I am looking to return the
    > following:
    >
    > <fabrikam:CustomerKey1 xmlns:fabrikam="http://blah.com">3333
    > <fabrikam:type>TYPE4</fabrikam:type>
    > </fabrikam:CustomerKey1>
    >
    > <fabrikam:CustomerKey2
    > xmlns:fabrikam="http://blah.com">4444</fabrikam:CustomerKey2>
    > <fabrikam:CustomerKey3
    > xmlns:fabrikam="http://blah.com">6666</fabrikam:CustomerKey3>
    >
    > I seem to agree with you that Xpath may not have a built-in function
    > for extracting an XML fragment as a string. If there is anyone else
    > out there who can provide input, I would greatly appreciat it.



    This is trivial using XSLT.

    Read about the
    xsl:copy-of

    xslt instruction.



    Cheers,
    Dimitre Novatchev
    Dimitre Novatchev, Oct 25, 2005
    #4
    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. Replies:
    0
    Views:
    1,399
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,364
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Murtaza Tinwala
    Replies:
    1
    Views:
    713
    Martin Honnen
    Sep 20, 2004
  4. Tjerk Wolterink
    Replies:
    2
    Views:
    1,399
    Dimitre Novatchev
    Aug 24, 2006
  5. jiing
    Replies:
    0
    Views:
    2,301
    jiing
    Apr 27, 2007
Loading...

Share This Page