473,830 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XPathDocument and retrieving xml string

I load an xml stream into a xpathdocument type, compile a xpath expression
and select to specific node. I find the node and wish to return the innerxml
of that node. When I use value of the current node I get back the "values"
of the child nodes but no formatted xml which I need for transformations
later in the sequence. Is there a way to pull pure xml from the
xpathdocument?
Nov 12 '05 #1
2 11937


Robert Strickland wrote:
I load an xml stream into a xpathdocument type, compile a xpath expression
and select to specific node. I find the node and wish to return the innerxml
of that node. When I use value of the current node I get back the "values"
of the child nodes but no formatted xml which I need for transformations
later in the sequence. Is there a way to pull pure xml from the
xpathdocument?


If you need access to the nodes as XmlNode objects then you need an
XmlDocument and not an XPathDocument, for instance try
using System;
using System.Xml;
using System.Xml.XPat h;

public class Test20031228 {

public static void Main (string[] args) {
XPathDocument xpathDocument = new XPathDocument(@ "test20031228.x ml");
XPathNavigator xpathNavigator = xpathDocument.C reateNavigator( );
TestXPathNaviga tor(xpathNaviga tor);

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Loa d(@"test2003122 8.xml");
xpathNavigator = xmlDocument.Cre ateNavigator();
TestXPathNaviga tor(xpathNaviga tor);
}

static void TestXPathNaviga tor (XPathNavigator xpathNavigator) {
XPathExpression xpathExpression = xpathNavigator. Compile("/*");
XPathNodeIterat or nodeIterator =
xpathNavigator. Select(xpathExp ression);
while (nodeIterator.M oveNext()) {
xpathNavigator = nodeIterator.Cu rrent;
IHasXmlNode hasXmlNode = xpathNavigator as IHasXmlNode;
if (hasXmlNode != null) {
XmlNode currentNode = hasXmlNode.GetN ode();
Console.WriteLi ne(currentNode. InnerXml);
}
else {
Console.WriteLi ne("Can't access nodes.");
}
}
}

}

and you will find that the cast to IHasXmlNode (which has the GetNode
method) fails for the navigator created from the XPathDocument while it
works for the navigator created from the XmlDocument.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #2
Thanks

"Martin Honnen" <Ma***********@ t-online.de> wrote in message
news:ea******** ******@TK2MSFTN GP10.phx.gbl...


Robert Strickland wrote:
I load an xml stream into a xpathdocument type, compile a xpath expression and select to specific node. I find the node and wish to return the innerxml of that node. When I use value of the current node I get back the "values" of the child nodes but no formatted xml which I need for transformations
later in the sequence. Is there a way to pull pure xml from the
xpathdocument?


If you need access to the nodes as XmlNode objects then you need an
XmlDocument and not an XPathDocument, for instance try
using System;
using System.Xml;
using System.Xml.XPat h;

public class Test20031228 {

public static void Main (string[] args) {
XPathDocument xpathDocument = new XPathDocument(@ "test20031228.x ml");
XPathNavigator xpathNavigator = xpathDocument.C reateNavigator( );
TestXPathNaviga tor(xpathNaviga tor);

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Loa d(@"test2003122 8.xml");
xpathNavigator = xmlDocument.Cre ateNavigator();
TestXPathNaviga tor(xpathNaviga tor);
}

static void TestXPathNaviga tor (XPathNavigator xpathNavigator) {
XPathExpression xpathExpression = xpathNavigator. Compile("/*");
XPathNodeIterat or nodeIterator =
xpathNavigator. Select(xpathExp ression);
while (nodeIterator.M oveNext()) {
xpathNavigator = nodeIterator.Cu rrent;
IHasXmlNode hasXmlNode = xpathNavigator as IHasXmlNode;
if (hasXmlNode != null) {
XmlNode currentNode = hasXmlNode.GetN ode();
Console.WriteLi ne(currentNode. InnerXml);
}
else {
Console.WriteLi ne("Can't access nodes.");
}
}
}

}

and you will find that the cast to IHasXmlNode (which has the GetNode
method) fails for the navigator created from the XPathDocument while it
works for the navigator created from the XmlDocument.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #3

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

Similar topics

1
4396
by: Ian Lawton | last post by:
Hi, in a C# app, I have an XPathDocument that looks similar to this: <row uniqueid="4234" /> <row uniqueid="4365" /> <row uniqueid="3124" /> <row uniqueid="9879" /> <row uniqueid="1332" /> <row uniqueid="4322" />
5
5645
by: xmlguy | last post by:
I believe this should be pretty elementary, but for some reason I cannot seem to think of how to write the an XML file from an incoming XML file. Basically this is what I do: Input: XmlReader instance from another module (beyond my control)
2
3719
by: xmlguy | last post by:
Cant seem to solve this problem I need to be able to re-use XmlReader and XPathDocument for an XSLT Transform. Basically I have defined following interfaces: Class Render (Common and public inside the class)
8
2464
by: Keith Chadwick | last post by:
My problem is this. I have to create several xmlReader objects each retrieving 'for xml' formatted sql server data. I then need to peice them together into a single document and place them into a single XPathDocument which is then transformed throughout the web site with different XslTransformations. I realize that the Xpathdocument will accept a XmlReader as an object but I have 5 of them so how to 'best' combine. The resulting...
2
2960
by: Keith Chadwick | last post by:
I have a merged dataset that contains xml read from SQL Server. I need to place the data into an XPathDocument. I can do the following: mydataset.writeXML("mydata.xml") dim xpdoc as new XPathDocument("mydata.xml") Problem is it seem rather redundent to write data currently in memory to disk in order to be read on the next line. According to the documentation
2
2486
by: Jim Lewis | last post by:
After everything I have read and some of my own testing I am convinced that XPathDocument are more efficient if you are only using XML for read only and not modifying the XML. However, I have been having problems doing same procedures I do with XPathDocuments in XPathDocuments. I have a configuration XML document, which holds all the configuration information for an application (see below sample). I extract the information from the...
3
1663
by: Atul | last post by:
Hi, I am getting XmlException while running the following code: string sConfigXPath = Constants.CONST_CONFIG_XPATH + ""; string sConfigFile = Constants.CONST_CONFIG_FILE_LOCATION; //Returns me the physical path @"C:\Temp\MyXml.xml" XPathDocument xpdConfig = new XPathDocument(sConfigFile,XmlSpace.Default); //XmlException raised here.
0
1059
by: Joe Pannone | last post by:
I need a way to allow a variable to equal an xml document. When using xpathdocument the parameter is asking for a filename. Since I plan on doing a lot of search in the xml document I would like to supply a variable instead of the xml doc. This is the code I use: dim docNav As XPathDocument docNav = New XPathDocument("c:\adsp_dispatch.xml") I would like to use something like:
1
1985
by: C#Schroeder | last post by:
First off I want to thank all that have helped me in the past. I am new to working with XML in .Net. I have another problem right now with my code. Background: I am trying to create a HTML document from some forms from a window application. I am creating a XML document from the forms, using a XSLT document, and populate a Web Broswer with the created HTML document. I want to create the XML document and HTML in memory rather then...
0
9781
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10769
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10522
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10197
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7740
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6944
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5777
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4408
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3072
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.