Solved

xml stored in a datatable, want to use XPathDocument with this xml data

Posted on 2007-12-06
2
799 Views
Last Modified: 2013-11-26
In my database I have an xml datatype column, when I fill a datatable with this xml data, the corresponding datatable column is now a string and not xml, so now I have a string which really is an xml document. I want to use XPathDocument, XPathNavigator, XPathExpression, etc to parse this xml document, but I can't figure out how to load the xml document.... I could create a tempory file based of this xml string and instantiate the XPathDocument this way, but would really not like to do that

All help is appreciated
Thanks
J
0
Comment
Question by:shmitnols
2 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 20422804
Hi shmitnols;

To load the string that has XML data into a XmlDataDocument see sample below.

Fernando
// Test string with XLM Data
string xmlData = "<?xml version=\"1.0\" encoding=\"utf-8\" ?> <configuration>        <system.web>      <compilation           defaultLanguage=\"c#\"          debug=\"true\"     />      <customErrors      mode=\"RemoteOnly\"      />       <authentication mode=\"Windows\" />        <authorization>         <allow users=\"*\" />      </authorization>      <trace         enabled=\"false\"         requestLimit=\"10\"         pageOutput=\"false\"         traceMode=\"SortByTime\" 		localOnly=\"true\"     />      <sessionState              mode=\"InProc\"             stateConnectionString=\"tcpip=127.0.0.1:42424\"             sqlConnectionString=\"data source=127.0.0.1;Trusted_Connection=yes\"             cookieless=\"false\"              timeout=\"20\"      />      <globalization              requestEncoding=\"utf-8\"              responseEncoding=\"utf-8\"     />      </system.web>  </configuration> ";
 
// Create an XML data document
XmlDataDocument xmlDatDoc = new XmlDataDocument();
// Load your XML data from a string in your code into the document
xmlDatDoc.LoadXml(xmlData);
 
// The following code just test to see that the string data was loaded
XmlTextWriter xtw = new XmlTextWriter("C:\\Temp\\xmlDocOut.xml", Encoding.UTF8);
xtw.Formatting = Formatting.Indented;
xmlDatDoc.WriteContentTo(xtw);
xtw.Flush();
xtw.Close();

Open in new window

0
 
LVL 29

Accepted Solution

by:
anarki_jimbel earned 500 total points
ID: 20422971
Try this link, they have same problem.

http://forums.asp.net/p/1112234/1718448.aspx

The link is in VB, so C# should be something like:


                string xml = @"<test></test>";
                System.IO.MemoryStream ms = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(xml));
                XPathDocument doc = new XPathDocument(ms);

Open in new window

0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question