XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(sampleXmlStr);
//In above line...utr string is loaded in to xmlDom. Here if instead of
//xDoc.LoadXml , u can use xDoc.Load(filePath) if ur xml is in some file.
//now see this variable.
string myData = xDoc.OuterXml;
//In above line u can see ur acutal xml.
//Weel to read this xml...u have to use xmlDom.. see this
//For Example if u want to read the value of Price where userID= "1" and ItemId = 3
//see the xml above..I have filled dummy values in it.
foreach (XmlAttribute xAtt in xNode.Attributes)
{
if (xAtt.Name.ToLower() == "price")
{
string myPrice = xAtt.Value;
}
}
//It wii give outpur as myPrice = 100.
/*FYI... It is very imporatan to know the xPath queries that can write to deal with xmlDoom
Here i have written the xQuery at Order[@UserId = 1]/OrderLine[@ItemId = 3]"
U can google out for more of this...Still if u need more help let me know.
*
*/
Please mark this post as Answer if it is of help to you!
I would love to change the world, but they wont give me the source code.
kavita_khand...
Star
9767 Points
1930 Posts
Re: how to convert String to XML and read this XML???
Jul 06, 2009 05:51 AM|LINK
string sampleXmlStr = "<Order UserId='1' CustomerId='101' TotalItem='3' TotalPrice='300'>"+
"<OrderLine ItemId='1' Quantity='1' DiscountValue='xxx' TaxValue='' Price='100'/>"+
"<OrderLine ItemId='2' Quantity='1' DiscountValue='xxx' TaxValue='' Price='100'/>" +
"<OrderLine ItemId='3' Quantity='1' DiscountValue='xxx' TaxValue='' Price='100'/></Order> ";
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(sampleXmlStr);
//In above line...utr string is loaded in to xmlDom. Here if instead of
//xDoc.LoadXml , u can use xDoc.Load(filePath) if ur xml is in some file.
//now see this variable.
string myData = xDoc.OuterXml;
//In above line u can see ur acutal xml.
//Weel to read this xml...u have to use xmlDom.. see this
//For Example if u want to read the value of Price where userID= "1" and ItemId = 3
//see the xml above..I have filled dummy values in it.
XmlNode xNode = xDoc.SelectSingleNode("Order[@UserId = 1]/OrderLine[@ItemId = 3]");
foreach (XmlAttribute xAtt in xNode.Attributes)
{
if (xAtt.Name.ToLower() == "price")
{
string myPrice = xAtt.Value;
}
}
//It wii give outpur as myPrice = 100.
/*FYI... It is very imporatan to know the xPath queries that can write to deal with xmlDoom
Here i have written the xQuery at Order[@UserId = 1]/OrderLine[@ItemId = 3]"
U can google out for more of this...Still if u need more help let me know.
*
*/
I would love to change the world, but they wont give me the source code.