<?xml version="1.0" encoding="utf-8"?> <DataConfiguration xmlns="abcefg12345" xmlns:xsi="12345abcefg" xsi:schemaLocation="12345abcefg12345abcefg"> <Hosts> <Sites> <Site Name="ss"> <Host Id="aa"> <Address Host="www.www.com"></Address> </Host> <Host Id="ee"> <Address Host="www.www.com"></Address> </Host> <Host Id="dd"> <Address Host="www.www.com"></Address> </Host> <Host Id="pp"> <Address Scheme="ppp" Host="www.www.com" Path="www.www.com" /> <Address Scheme="ppp" Host="www.www.com" Path="www.www.com/" /> </Host> <Host Id="ss"> <Address Scheme="ppp" Host="www.www.com" Path="www.www.com" /> <Address Scheme="ppp" Host="www.www.com" Path="www.www.com" /> </Host> <Host Id="561"> <Address Host="www.www.com"></Address> </Host> </Site> <Site Name="hihi"> <Host Id="cc"> <Address Host="www.www.com"></Address> </Host> <Host Id="sdD"> <Address Host="www.www.com"></Address> </Host> <Host Id="8uj"> <Address Scheme="ppp" Host="www.www.com" Path="www.www.com" /> <Address Scheme="ppp" Host="www.www.com" Path="www.www.com" /> </Host> <Host Id="222"> <Address Scheme="ppp" Host="www.www.com" Path="www.www.com" /> <Address Scheme="ppp" Host="www.www.com" Path="www.www.com" /> </Host> <Host Id="hhh"> <Address Scheme="ppp" Host="www.www.com" Path="www.www.com" /> </Host> <Host Id="hhh"> <Address Scheme="ppp" Host="www.www.com" Path="www.www.com" /> </Host> </Site> </Sites> <Host Id="hhh"> <Address Scheme="ppp" Host="www.www.com" Path="www.www.com" /> </Host> <Host Id="hhh"> <Address Scheme="ppp" Host="www.www.com" Path="www.www.com" /> </Host> <Host Id="hhh"> <Address Scheme="ppp" Host="www.www.com" Path="www.www.com" /> </Host> <Host Id="hhh"> <Address Scheme="ppp" Host="www.www.com" Path="www.www.com" /> </Host> </Hosts> <DataPools> <DataPool Id="sss" default="sure"> <DataGroup Id="sss" Parent="aaa" UserCanSelectHost="sure"> <HostId Parent="hhhh">I'm breaking here</HostId> <DataSources> <empty/> </DataSources> </DataGroup> <DataGroup Id="ccc" UserCanSelectHost="whynot"> <HostId>God I'm breaking here again, i hope you can fix me</HostId> <DataSources> <empty/> </DataSources> </DataGroup> <DataGroup Id="sss" UserCanSelectHost="yessure"> <HostId>cry face</HostId> <webfg displaygroup="sss" provider="sss">
private void AddNode(XmlNode inXmlNode, TreeNode inTreeNode) { // Loop through the XML nodes until the leaf is reached. // Add the nodes to the TreeView during the looping process. if (inXmlNode.HasChildNodes) { //Check if the XmlNode has attributes foreach (XmlAttribute att in inXmlNode.Attributes) { inTreeNode.Text = inTreeNode.Text + " " + att.Name + ": " + att.Value; } var nodeList = inXmlNode.ChildNodes; for (int i = 0; i < nodeList.Count; i++) { var xNode = inXmlNode.ChildNodes[i]; var tNode = inTreeNode.Nodes[inTreeNode.Nodes.Add(new TreeNode(xNode.Name))]; AddNode(xNode, tNode); } } else { // Here you need to pull the data from the XmlNode based on the // type of node, whether attribute values are required, and so forth. inTreeNode.Text = (inXmlNode.OuterXml).Trim(); } treeView1.ExpandAll(); }
すべてのノードが要素名と属性データを子供を持つだけでなく、テキストノードのみにoutherxmlを使用することを確認するに
以上が属性を含む XML を C# TreeView に解析するときに重複する属性の表示を防ぐ方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。