How to Convert string into XML format [closed]
How can I convert this string into XML?
string sTemp = "<message>
<Category>
<Category ID=""null|1"" Category Name=""null|SampleCategory1""/>
<Category ID=""null|2"" Category Name=""null|Sa开发者_运维问答mpleCategory2""/>
<Category/>
<ProductDetails Type=""PDF|SWF|DOC|PPT|XLS|HTML|STREAMING"" Status=""Activated|Expired"" Version=""1.0"" FilePathURL=""http://test.mylytica.com/Uploads/PPPC.pdf"" ProductDescription=""null|Text"" VersionDescription=""null|Text"" Author=""null|authorname"" Validity=""null|date|NeverExpiry"" >
</ProductDetails >
</message>
";
use XElement.Parse
var element = XElement.Parse(sTemp);
Use XmlDocument
http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx
and its Load
method.
http://msdn.microsoft.com/en-us/library/875kz807.aspx
I like using XDocument, it has a lot of nice functionality for creating and editing xml documents. It also gives some nice access to the Linq statments for getting the information out without having to loop through all the elements.
try
{
XDocument doc = XDocument.Parse(text);
}
catch(Exception _ex)
{
Console.WriteLine(_ex.Message);
}
精彩评论