Solved

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

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

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now