0

您好,我需要在控制台应用程序中使用 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

4

2 回答 2

0

使用 linq2xml :

XElement xmlTree = XElement.Parse("<TREE_MENU_NESTED>... ");
Console.WriteLine(xmlTree);
于 2012-04-26T19:45:34.380 回答
0

您可以使用 Linq to Xml

XElement doc = XElement.Parse("You XML text");

foreach (XElement treeNode in doc.Elements())
    Console.WriteLine(treeNode.Value);
于 2012-04-26T19:50:32.167 回答