removing xml attributes [modified]
-
hi everyone, i want to get all the attributes of an element and put them under that element. but i don't know why at some elements their attributes are displayed beside it and i want to get rid of the namespace too. see the code below and tell me what's wrong with it. private void populateTreeView(XmlNode node2Iterate, TreeNode currNode) { XmlNode xNode; TreeNode tNode; XmlNodeList nodeList; TreeNode attrNode = new TreeNode(); if (node2Iterate.HasChildNodes) { nodeList = node2Iterate.ChildNodes; for(int i = 0; i<=nodeList.Count - 1; i++) { TreeNode tn; xNode = node2Iterate.ChildNodes[i]; tn = new TreeNode("<" + xNode.Name + ">"); currNode.Nodes.Add(tn); tNode = currNode.Nodes[i]; populateTreeView(xNode, tNode); if(node2Iterate.ChildNodes[i].Attributes != null) { foreach(XmlAttribute attr in node2Iterate.ChildNodes[i].Attributes) { string attrs = null; attrs = "<" + attr.Name + "=\"" + attr.Value + "\"" +">"; currNode.Nodes[i].Nodes.Add(attrs); } } } } else { currNode.Text = (node2Iterate.OuterXml).Trim(); } } the output looks like this on a treeView control: - - - thanks for any help! -- modified at 23:41 Monday 2nd October, 2006
-
hi everyone, i want to get all the attributes of an element and put them under that element. but i don't know why at some elements their attributes are displayed beside it and i want to get rid of the namespace too. see the code below and tell me what's wrong with it. private void populateTreeView(XmlNode node2Iterate, TreeNode currNode) { XmlNode xNode; TreeNode tNode; XmlNodeList nodeList; TreeNode attrNode = new TreeNode(); if (node2Iterate.HasChildNodes) { nodeList = node2Iterate.ChildNodes; for(int i = 0; i<=nodeList.Count - 1; i++) { TreeNode tn; xNode = node2Iterate.ChildNodes[i]; tn = new TreeNode("<" + xNode.Name + ">"); currNode.Nodes.Add(tn); tNode = currNode.Nodes[i]; populateTreeView(xNode, tNode); if(node2Iterate.ChildNodes[i].Attributes != null) { foreach(XmlAttribute attr in node2Iterate.ChildNodes[i].Attributes) { string attrs = null; attrs = "<" + attr.Name + "=\"" + attr.Value + "\"" +">"; currNode.Nodes[i].Nodes.Add(attrs); } } } } else { currNode.Text = (node2Iterate.OuterXml).Trim(); } } the output looks like this on a treeView control: - - - thanks for any help! -- modified at 23:41 Monday 2nd October, 2006
I think the problem is the following line:
currNode.Text = (node2Iterate.OuterXml).Trim();
Use the
LocalName
property instead ofOuterXml
.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
-
I think the problem is the following line:
currNode.Text = (node2Iterate.OuterXml).Trim();
Use the
LocalName
property instead ofOuterXml
.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
thanks alot for your reply, that fixed my problem:-D