开发者

How to Convert string into XML format [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜