472,110 Members | 2,097 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,110 software developers and data experts.

Append XML document

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 '06 #1
4 3347

<gl****@yahoo.comwrote in message
news:11**********************@73g2000cwn.googlegro ups.com...
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 '06 #2
Thanks, I'll go through it.

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

Anthony Jones wrote:
<gl****@yahoo.comwrote in message
news:11**********************@73g2000cwn.googlegro ups.com...
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 '06 #3
gl****@yahoo.com 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 <dataroottag. 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 '06 #4
Bob,

Yes, the <dataroottag is in the XML file, I just removed it for the
posting.

Thanks for the help!!

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

Bob Barrows [MVP] wrote:
gl****@yahoo.com 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 <dataroottag. 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 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by brian | last post: by
3 posts views Thread by J Krugman | last post: by
8 posts views Thread by Kelly Sellers | last post: by
3 posts views Thread by juicy | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.