如何在ASP.NET网页中显示XML文件内容
大家好,
我想在asp.net中使用C#开发一个用于以下样本XML文件的UI。
我知道我们可以进行XSLT转换,在谷歌搜索之后,在xslt中我们可以提到简单的HTML UI控件。我需要asp.net服务器控件并需要在页面后面的代码中处理它的事件。
我也知道,在阅读XML并准备一个xaml之后在WPF中将xaml提供给渲染控件,它将显示给UI
但我正在寻找asp.net webForm页面
有没有人建议最好的方法来跟随一些样品?
样本XML文件
Hi Guys,
I would like to develop an UI in asp.net using C# for below kind of sample XML file.
I know we can go for XSLT transformations, after googling, in xslt we can mention plain HTML UI control. What I need to asp.net server controls and need to handle its events in code behind page.
I also know, in WPF after reading XML and prepare a xaml and give xaml to a render control, which will take care of displaying to UI
But I’m looking in asp.net webForm pages
Could anyone suggest best approach to follow with some samples?
Sample XML file
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Root>
<Users>
<FirstName value="TestFirst" />
<LastName value="TestLast"/>
</Users>
<Machine>
<Name value="" host="" sycTime="1" maxCount="10" />
<url>http://255.255.255:8008</url>
</Machine>
<UISampleOne>
<Checkboxes value="true" />
<Columns>
<column columntext="FirstName" width="" datatype="string" isreadonly="true" />
<column columntext=" LastName " width="" datatype="date" isreadonly="false" />
<column columntext="Date" width="" datatype="date" isreadonly="false" />
</Columns >
<Filter>
<FilterType value="FirstName" label="string" />
<FilterType value="LastName" label="string" />
</Filter>
</UISampleOne>
<UISampleTwo>
<SectionOne>
<FName value="SectionFName" />
<LName value="SectionLName"/>
</SectionOne>
<SectionTwo>
<FName value="SectionFName" />
<LName value="SectionLName"/>
</SectionTwo>
</UISampleTwo>
<UISampleThree>
<ListsOne>
<list list_name="ListName1" list_path="/ABC/Xyz">
<item item_text="ItemText" item_name="ItemName1"/>
<item item_text="ItemText" item_name="ItemName1"/>
</list>
<list list_name="ListName2" list_path="/ABC2/Xyz2">
<item item_text="ItemText" item_name="ItemName1"/>
<item item_text="ItemText" item_name="ItemName1"/>
</list>
</ListsOne >
<ListsTwo>
<list list_name="ListName1" list_path="/ABC/Xyz">
<item item_text="ItemText" item_name="ItemName1"/>
<item item_text="ItemText" item_name="ItemName1"/>
</list>
<list list_name="ListName2" list_path="/ABC2/Xyz2">
<item item_text="ItemText" item_name="ItemName1"/>
<item item_text="ItemText" item_name="ItemName1"/>
</list>
</ListsTwo>
</UISampleThree>
</Root>
我尝试了什么:
我知道我们可以google用于XSLT转换,在xslt中我们可以提到简单的HTML UI控件。我需要asp.net服务器控件并需要在页面后面的代码中处理它的事件。
我也知道,在阅读XML并准备一个xaml之后在WPF中将xaml提供给渲染控件,它将显示到UI
但我正在查看asp.net webForm页面
What I have tried:
I know we can go for XSLT transformations, after googling, in xslt we can mention plain HTML UI control. What I need to asp.net server controls and need to handle its events in code behind page.
I also know, in WPF after reading XML and prepare a xaml and give xaml to a render control, which will take care of displaying to UI
But I’m looking in asp.net webForm pages
我可以建议你遍历XML文件并获取节点。例如,我使用下面的代码来读取我的xml文件中的XML节点,我得到的值在每个节点中,然后分配给一个变量。
Hi,i can advise that you loop through the XML file and get the nodes.For example,i have used the below code to read the XML nodes in my xml file which i am getting the values in each node and then assigning to a variable.
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(yourxmlfilestring);
XmlNodeList machineNodeList= xmlDocument.GetElementsByTagName("Machine");
foreach (XmlNode value in machineNodeList)
{
//while doing the loop here,get the actual values by using value.InnerText to get the actual value
}