从XML文件填充项目符号列表中的数据 [英] Populate data in Bullet list from XML File
问题描述
我有一个XML文件,例如:
<教育>
<教育>学士学位</education>
< education> 2年经验</education>
<教育>我的技能:
< Skill> C#</Skill>
< Skill> Asp.net</Skill>
<技能> SQL Server</技能>
</education>
</教育>
我想从XML文件上方提取数据并显示在项目符号列表中,如下所示:
*学士学位
* 2年经验
*我的技能:
* C#
* Asp.net
* SQL Server
I have an XML file, like this :
<Educations>
<education>Bachelor Degree</education>
<education>2 Year Experience</education>
<education>My Skills:
<Skill>C#</Skill>
<Skill>Asp.net</Skill>
<Skill>SQL Server</Skill>
</education>
</Educations>
I want to Extract data from above XML File and show in Bullet list, like this:
*Bachelor Degree
*2 Year Experience
*My Skills:
*C#
*Asp.net
*SQL Server
推荐答案
在这里,我尝试了一些代码来满足您的要求,以将XML显示为项目符号列表
试试这个
Hi,
Here I tried some code for your requirement to display your xml as bullet list
try this
<div id="bulletlistid" runat="server"></div>
文件后面的代码包含以下代码
And code behind file contains following code
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("~/SomeFiles/XMLFile5.xml"));
XmlNodeList xmlnodelst = xmldoc.GetElementsByTagName("education");
StringBuilder sb = new StringBuilder(" <ul style="\"list-style-type:" mode="hold" /> if (xmlnodelst.Count > 0)
{
foreach (XmlNode g in xmlnodelst )
{
if (g.ChildNodes.Count >1)
{
XmlNodeList xmlnodelst1 = g.ChildNodes;
int j = 0;
foreach (XmlNode h in xmlnodelst1)
{
if (j == 0)
{
sb.Append("<li>" + h.InnerText + "<ul>");
j++;
}
else
{
sb.Append("<li>" + h.InnerText + "</li>");
}
}
sb.Append("</ul></li>");
}
else
{
sb.Append("<li>"+g.InnerText +"</li>");
}
}
}
sb.Append("");
bulletlistid.InnerHtml = sb.ToString();
在上面的代码中,我希望您知道您必须更改文件路径.
最好的
In the above code I hope you know that you''ve to change filepath.
All the Best
这篇关于从XML文件填充项目符号列表中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!