Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. removing xml attributes [modified]

removing xml attributes [modified]

Scheduled Pinned Locked Moved C#
xmlhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lagumaster
    wrote on last edited by
    #1

    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

    S 1 Reply Last reply
    0
    • L lagumaster

      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

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      I think the problem is the following line:

      currNode.Text = (node2Iterate.OuterXml).Trim();

      Use the LocalName property instead of OuterXml.


      "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

      www.troschuetz.de

      L 1 Reply Last reply
      0
      • S Stefan Troschuetz

        I think the problem is the following line:

        currNode.Text = (node2Iterate.OuterXml).Trim();

        Use the LocalName property instead of OuterXml.


        "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

        www.troschuetz.de

        L Offline
        L Offline
        lagumaster
        wrote on last edited by
        #3

        thanks alot for your reply, that fixed my problem:-D

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups