?
Solved

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

Posted on 2007-12-06
2
Medium Priority
?
803 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 30

Accepted Solution

by:
anarki_jimbel earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

800 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