你好我需要在控制台应用程序中用C#解析这个xml,有什么帮助吗?
<TREE_MENU_NESTED>
<TREE>Category I
<TREE ACTION="URL" LINK="c1/p1.html" TARGET="_self" ICON="icon_slide" >Product 1</TREE>
<TREE ACTION="URL" LINK="c2/p2.html" TARGET="_self" ICON="icon_slide" >Product 2</TREE>
</TREE>
<TREE>Category II
<TREE ACTION="URL" LINK="c2/p1.html" TARGET="_self" ICON="icon_slide" >Product 1</TREE>
<TREE ACTION="URL" LINK="c2/p2.html" TARGET="_self" ICON="icon_slide" >Product 2</TREE>
</TREE>
</TREE_MENU_NESTED>
需要在控制台中显示:
--category 1:product1,product 2
--category 2:product1,product 2
答案 0 :(得分:0)
使用linq2xml:
XElement xmlTree = XElement.Parse("<TREE_MENU_NESTED>... ");
Console.WriteLine(xmlTree);
答案 1 :(得分:0)
您可以使用Linq to Xml
XElement doc = XElement.Parse("You XML text");
foreach (XElement treeNode in doc.Elements())
Console.WriteLine(treeNode.Value);