Append Node to an XML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Freddy Coal

    #1

    Append Node to an XML

    Hi, I would like append a new node with elements in a existing XML file, how
    make that?.

    For example:

    <?xml version="1.0" encoding="utf-8" ?>
    - <Configuracio n>
    - <Estaciones>
    <Capa_Trabajo>C :\Temp\point.sh p</Capa_Trabajo>
    <Estados>C:\Tem p\WGS84_region. shp</Estados>
    <IndexA>1</IndexA>
    <Date>Date=21/03/2007 09:55:52</Date>
    </Estaciones>
    </Configuracion>

    I would like append a node, how make this node?

    <Links>
    <SiteAontario </SiteA>
    <SiteBCanton </SiteB>
    </Links>

    And my final XML is:

    <?xml version="1.0" encoding="utf-8" ?>
    - <Configuracio n>
    - <Estaciones>
    <Capa_Trabajo>C :\Temp\point.sh p</Capa_Trabajo>
    <Estados>C:\Tem p\WGS84_region. shp</Estados>
    <IndexA>1</IndexA>
    <Date>Date=21/03/2007 09:55:52</Date>
    </Estaciones>
    <Links>
    <SiteAontario </SiteA>
    <SiteBCanton </SiteB>
    </Links>
    </Configuracion>

    Thanks in advance.

    Freddy Coal


  • Rick

    #2
    Re: Append Node to an XML

    I'm not sure what net component you are using in your program for the
    existing xml, however you can lookup XmlFragment in the help. You create an
    XmlFragment from the source document and then AppendChile (or something
    similar) to add it to the document.

    Rick

    Hi, I would like append a new node with elements in a existing XML file,
    how make that?.
    >
    >

    Comment

    • Martin Honnen

      #3
      Re: Append Node to an XML

      Freddy Coal wrote:
      I would like append a node, how make this node?
      >
      <Links>
      <SiteAontario </SiteA>
      <SiteBCanton </SiteB>
      </Links>
      >
      And my final XML is:
      >
      <?xml version="1.0" encoding="utf-8" ?>
      - <Configuracio n>
      - <Estaciones>
      <Capa_Trabajo>C :\Temp\point.sh p</Capa_Trabajo>
      <Estados>C:\Tem p\WGS84_region. shp</Estados>
      <IndexA>1</IndexA>
      <Date>Date=21/03/2007 09:55:52</Date>
      </Estaciones>
      <Links>
      <SiteAontario </SiteA>
      <SiteBCanton </SiteB>
      </Links>
      </Configuracion>
      Use the DOM implementation in the .NET framework, that is
      System.Xml.XmlD ocument:

      Dim XmlDoc As XmlDocument = New XmlDocument()
      XmlDoc.Load("fi le.xml")

      Dim Links As XmlElement = XmlDoc.CreateEl ement("Links")
      Dim SiteA As XmlElement = XmlDoc.CreateEl ement("SiteA")
      SiteA.InnerText = "ontario"
      Dim SiteB As XmlElement = XmlDoc.CreateEl ement("SiteB")
      SiteB.InnerText = "Canton"
      Links.AppendChi ld(SiteA)
      Links.AppendChi ld(SiteB)

      XmlDoc.Document Element.AppendC hild(Links)

      XmlDoc.Save("fi le.xml")


      --

      Martin Honnen --- MVP XML
      http://JavaScript.FAQTs.com/

      Comment

      Working...