Append XML document

Discussion in 'ASP General' started by glbdev@yahoo.com, Dec 12, 2006.

  1. Guest

    Hi,

    I posted this in "microsoft.public.xml.msxml-webrelease" but now
    realize it should probably have been in the ASP group. Sorry if that
    causes any problems.

    I have an XML document like:
    <MainNode>
    <Value>First Value</Value>
    </MainNode>
    <MainNode>
    <Value>Second Value</Value>
    </MainNode>
    <MainNode>
    <Value>Third Value</Value>
    </MainNode>
    <MainNode>
    <Value>Fourth Value</Value>
    </MainNode>
    </dataroot>

    I need to append information to this file using ASP. How do I do this?
    I am just starting out in XML so sample code would really help.

    Also, I may need to remove a node from this file ... is that possible?
    If so, how?

    Thanks!!
    - Gary
     
    , Dec 12, 2006
    #1
    1. Advertising

  2. <> wrote in message
    news:...
    > Hi,
    >
    > I posted this in "microsoft.public.xml.msxml-webrelease" but now
    > realize it should probably have been in the ASP group. Sorry if that
    > causes any problems.
    >
    > I have an XML document like:
    > <MainNode>
    > <Value>First Value</Value>
    > </MainNode>
    > <MainNode>
    > <Value>Second Value</Value>
    > </MainNode>
    > <MainNode>
    > <Value>Third Value</Value>
    > </MainNode>
    > <MainNode>
    > <Value>Fourth Value</Value>
    > </MainNode>
    > </dataroot>
    >
    > I need to append information to this file using ASP. How do I do this?
    > I am just starting out in XML so sample code would really help.
    >
    > Also, I may need to remove a node from this file ... is that possible?
    > If so, how?
    >
    > Thanks!!
    > - Gary
    >


    Have a run through this tutorial:-

    http://www.w3schools.com/dom/default.asp

    also:-

    http://www.w3schools.com/xpath/default.asp
     
    Anthony Jones, Dec 12, 2006
    #2
    1. Advertising

  3. Guest

    Thanks, I'll go through it.

    - Gary
    ------------------------------------------------------------------------------------------------------------------------
    -----------------------------------------------------------------------------------------------------------------------

    Anthony Jones wrote:
    > <> wrote in message
    > news:...
    > > Hi,
    > >
    > > I posted this in "microsoft.public.xml.msxml-webrelease" but now
    > > realize it should probably have been in the ASP group. Sorry if that
    > > causes any problems.
    > >
    > > I have an XML document like:
    > > <MainNode>
    > > <Value>First Value</Value>
    > > </MainNode>
    > > <MainNode>
    > > <Value>Second Value</Value>
    > > </MainNode>
    > > <MainNode>
    > > <Value>Third Value</Value>
    > > </MainNode>
    > > <MainNode>
    > > <Value>Fourth Value</Value>
    > > </MainNode>
    > > </dataroot>
    > >
    > > I need to append information to this file using ASP. How do I do this?
    > > I am just starting out in XML so sample code would really help.
    > >
    > > Also, I may need to remove a node from this file ... is that possible?
    > > If so, how?
    > >
    > > Thanks!!
    > > - Gary
    > >

    >
    > Have a run through this tutorial:-
    >
    > http://www.w3schools.com/dom/default.asp
    >
    > also:-
    >
    > http://www.w3schools.com/xpath/default.asp
     
    , Dec 12, 2006
    #3
  4. wrote:
    > Hi,
    >
    > I posted this in "microsoft.public.xml.msxml-webrelease" but now
    > realize it should probably have been in the ASP group. Sorry if that
    > causes any problems.
    >
    > I have an XML document like:
    > <MainNode>
    > <Value>First Value</Value>
    > </MainNode>
    > <MainNode>
    > <Value>Second Value</Value>
    > </MainNode>
    > <MainNode>
    > <Value>Third Value</Value>
    > </MainNode>
    > <MainNode>
    > <Value>Fourth Value</Value>
    > </MainNode>
    > </dataroot>


    this is not legal xml - it's missing a <dataroot> tag. I will assume the
    xml actually starts with that tag.

    >
    > I need to append information to this file using ASP. How do I do
    > this? I am just starting out in XML so sample code would really help.
    >
    > Also, I may need to remove a node from this file ... is that possible?
    > If so, how?

    Where is this xml coming from? A file? Are you building it in code? I
    will assume it is contained in a file:

    <%
    dim xmldoc, root, node
    set xmldoc=createobject("msxml2.domdocument")
    xmldoc.load("filename.xml")
    set root = xmldoc.documentelement

    'To add a MainNode with "Fifth Value", do this:
    set node = xmldoc.createelement("MainNode")
    node.text = "Fifth Value"
    root.appendchild node
    response.write xmldoc.xml & "<br><hr>"

    'To remove the "Second Value" node:
    set node=nothing
    set node = xmldoc.selectsinglenode("//MainMode[. = 'Second Value']")
    if not node is nothing then
    root.removechild node
    end if
    response.write xmldoc.xml & "<br><hr>"
    %>

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Dec 12, 2006
    #4
  5. Guest

    Bob,

    Yes, the <dataroot> tag is in the XML file, I just removed it for the
    posting.

    Thanks for the help!!

    - Gary
    --------------------------------------------------------------------------------------------------------

    Bob Barrows [MVP] wrote:
    > wrote:
    > > Hi,
    > >
    > > I posted this in "microsoft.public.xml.msxml-webrelease" but now
    > > realize it should probably have been in the ASP group. Sorry if that
    > > causes any problems.
    > >
    > > I have an XML document like:
    > > <MainNode>
    > > <Value>First Value</Value>
    > > </MainNode>
    > > <MainNode>
    > > <Value>Second Value</Value>
    > > </MainNode>
    > > <MainNode>
    > > <Value>Third Value</Value>
    > > </MainNode>
    > > <MainNode>
    > > <Value>Fourth Value</Value>
    > > </MainNode>
    > > </dataroot>

    >
    > this is not legal xml - it's missing a <dataroot> tag. I will assume the
    > xml actually starts with that tag.
    >
    > >
    > > I need to append information to this file using ASP. How do I do
    > > this? I am just starting out in XML so sample code would really help.
    > >
    > > Also, I may need to remove a node from this file ... is that possible?
    > > If so, how?

    > Where is this xml coming from? A file? Are you building it in code? I
    > will assume it is contained in a file:
    >
    > <%
    > dim xmldoc, root, node
    > set xmldoc=createobject("msxml2.domdocument")
    > xmldoc.load("filename.xml")
    > set root = xmldoc.documentelement
    >
    > 'To add a MainNode with "Fifth Value", do this:
    > set node = xmldoc.createelement("MainNode")
    > node.text = "Fifth Value"
    > root.appendchild node
    > response.write xmldoc.xml & "<br><hr>"
    >
    > 'To remove the "Second Value" node:
    > set node=nothing
    > set node = xmldoc.selectsinglenode("//MainMode[. = 'Second Value']")
    > if not node is nothing then
    > root.removechild node
    > end if
    > response.write xmldoc.xml & "<br><hr>"
    > %>
    >
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.
     
    , Dec 12, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. barry
    Replies:
    3
    Views:
    599
    barry
    Dec 23, 2005
  2. Tony Prichard
    Replies:
    0
    Views:
    754
    Tony Prichard
    Dec 12, 2003
  3. Manish Hatwalne
    Replies:
    1
    Views:
    405
    Martin Honnen
    Jul 13, 2004
  4. HYRY
    Replies:
    10
    Views:
    625
    Bruno Desthuilliers
    Sep 26, 2007
  5. Koms Bomb
    Replies:
    1
    Views:
    122
    Koms Bomb
    Jul 1, 2003
Loading...

Share This Page