473,473 Members | 1,475 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XPath Convert Node to String

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 '05 #1
3 6938


ss*****@gmail.com 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/
Oct 24 '05 #2
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 '05 #3

<ss*****@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
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
Oct 25 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
1
by: inquirydog | last post by:
Can anyone explain to me why the following XQuery expression (a simple xpath expression) returns a different result than the same expression in xslt? document("document.xml")//a/@b For the...
9
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they...
3
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer>...
5
by: Gnic | last post by:
Hi , I have an XmlDocument instance, I want to find a node in the xml, but I don't know it's path until runtime, for example <aaa> <bbb name="x"/> <aaa attr="y"> <ccc>sometext</ccc> </aaa>
9
by: DBC User | last post by:
Hi, I have an xml and I am able to use xpath to identify each node that statisfy the selection criteria. I got the node list. I would like to know is it possible to do the following for the...
3
by: Bloody Viking | last post by:
Namaste, Y'all! I've got a valid XQuery expression that I need to convert to XPath 2.0. This expression will be stored in a resource file and applied to XML by a Java program with saxon8.jar...
2
by: surya926 | last post by:
Hello! I want to generate dynamicaly xpath in c#.net code from xml file which is having multiple child elements under parent element.The purpose of generating xpath is uses for calculation.The...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.