日期:2014-05-18 浏览次数:21101 次
XmlDocument x = new XmlDocument();
x.Load("..\\..\\a.xml");
XmlNode n = x.SelectSingleNode("/root/a");
XmlNodeList nl = n.ChildNodes;
foreach (XmlNode no in nl)
{
if (no.NodeType == XmlNodeType.Element)
richTextBox1.AppendText(no.Name + "\r\n");
}
for (int i = 0; i < n.Attributes.Count; i++)
{
richTextBox1.AppendText(n.Attributes[i].Name + "\r\n");
}
------解决方案--------------------
XmlDocument doc = new XmlDocument();
doc.Load(@"D:\Project\C#Test\WindowsApplication1\WindowsApplication2\XMLFile3.xml");
XmlNode node = doc.SelectSingleNode("/root/a");
foreach (XmlNode el in node.ChildNodes)
{
if (el.Name != "e")
{
Debug.WriteLine("nodeType:"+el.NodeType);
Debug.WriteLine("Text:" + el.InnerText);
if (el.Attributes != null)
{
foreach (XmlAttribute att in el.Attributes)
{
Debug.WriteLine("XmlAttribute:" + att.InnerText);
}
}
}
}
------解决方案--------------------
XmlDocument x = new XmlDocument();
x.Load(Application.StartupPath+"\\a.xml");
XmlNodeList n = x.SelectNodes("/root/a");
foreach (XmlNode xm in n)
{
for (int i = 0; i < xm.Attributes.Count; i++)
{
richTextBox1.AppendText(xm.Attributes[i].Name + "--" + xm.Attributes[i].Value + "\r\n");
}
XmlNodeList nl = xm.ChildNodes;
foreach (XmlNode no in nl)
{
if (no.NodeType == XmlNodeType.Element)
richTextBox1.AppendText(no.Name + "--" + no.InnerText + "\r\n");
}
}
------解决方案--------------------
LZ把想要的结果写出个例子来.这样大家好有目标.
在问题上加个补充.
------解决方案--------------------
XmlDocument x = new XmlDocument();
x.Load(Application.StartupPath+"\\a.xml");
XmlNodeList n = x.SelectNodes("/root/a");
foreach (XmlNode xm in n)
{
richTextBox1.AppendText("a:element");
for (int i = 0; i < xm.Attributes.Count; i++)
{
richTextBox1.AppendText(" attribute:"+xm.Attributes[i].Name + " value="+xm.Attributes[i].Value );
}
richTextBox1.AppendText("\r\n");
XmlNodeList nl = xm.ChildNodes;
foreach (XmlNode no in nl)
{
if (no.NodeType == XmlNodeType.Element)
richTextBox1.AppendText(" element:"+no.Name + " value=" + no.InnerText);
}
richTextBox1.AppendText("\r\n");
}