Solved

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

Posted on 2007-12-06
2
798 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

831 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