Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2007-12-06
2
Medium Priority
?
805 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 64

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

604 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