Currently I have xml stored in a ms sql dbase and not a file. Here's a small sample.
<NewDataSet>
<Table1>
<billTo_lastName>asdf</billTo_lastName>
<orderAmount>160.00</orderAmount>
<billTo_street1>asdf</billTo_street1>
<card_accountNumber>############1111</card_accountNumber>
</Table1>
</NewDataSet>
Currently I'm returning the result in a Datable.
What would be the best way to parse the above and display it on a page. The page display is just for informational review. No additional processing will be done to the xml.
I would like the page to display something along these lines.
billTo_lastName: asdf
orderAmount: 160.00
etc.
First, the sp_xml_preparedocument stored procedure parses the XML document. The parsed document is a tree representation of the nodes (elements, attributes, text, and comments) in the XML document. OPENXML then refers to this parsed XML document and provides a rowset view of all or parts of this XML document.
To parse XML documents, use the XML PARSE statement, specifying the XML document that is to be parsed and the processing procedure for handling XML events that occur during parsing, as shown in the following code fragment.
First approach: Load the XML file into an XML table and then parse it. First, create a table in Oracle that includes a column with data type XMLTYPE. For example, use the following code to create the table: CREATE TABLE xml_tab ( File_name varchar2(100), xml_data XMLTYPE );
Depends on how you want to process it. One way is to create an XmlDocument
and then call LoadXml:
// get the data from the data table, into a string.
// then create an XML document and load the string
var doc = new XmlDocument();
doc.LoadXml(dataString);
If you want to use Linq-to-Xml, you'd create an XElement:
var element = XElement.Load(dataString);
Thanks to Jim for pointing me in the right direction. XmlDocuments LoadXml works just fine. I then was able to put that into an XmlNodeList and selected the top node. Did XmlNode and looped through the child nodes.
DataTable dt = sqlselect(sqlQuery, parameter);
var doc = new XmlDocument();
doc.LoadXml(dt.Rows[0]["ua_post"].ToString());
XmlNodeList nl = doc.SelectNodes("NewDataSet");
XmlNode root = nl[0];
foreach (XmlNode xnode in root.ChildNodes[0])
{
string name = xnode.Name;
string value = xnode.InnerText;
string nv = "<b>" + name + ":</b> " + value;
Label1.Text += nv + " <br />" + Environment.NewLine;
}
And I get a simple display on a page.
billTo_lastName: asdf
orderAmount: 160.00
billTo_street1: asdf
card_accountNumber: ############1111
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With