Discussion:
Append XML document?
(too old to reply)
g***@yahoo.com
2006-12-12 15:01:44 UTC
Permalink
Hi,

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
Martin Honnen
2006-12-12 15:25:41 UTC
Permalink
Post by g***@yahoo.com
<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>
Where is the opening <dataroot> tag?
Post by g***@yahoo.com
I need to append information to this file using ASP. How do I do this?
With classic ASP you use MSXML to load the file, create new elements,
insert them and save the file back e.g.
Dim XmlDoc : Set XmlDoc = CreateObject("Msxml2.DOMDocument.3.0")
XmlDoc.async = False
If XmlDoc.load(Server.MapPath("file.xml")) Then
Dim Main : Set Main = XmlDoc.createElement("MainNode")
Dim Value : Set Value = XmlDoc.createElement("Value")
Value.appendChild(XmlDoc.createTextNode("Fifth Value"))
Main.appendChild(Value)
XmlDoc.documentElement.appendChild(Main)
XmlDoc.Save(Server.MapPath("file.xml"))
Else
' deal with parse error here
End If
Post by g***@yahoo.com
Also, I may need to remove a node from this file ... is that possible?
Find the node using XPath e.g.
XmlDoc.setProperty "SelectionLanguage", "XPath"
Set Main = _
XmlDoc.selectSingleNode("/dataroot/MainNode[Value = 'Third Value']")
then call removeChild e.g.
Main.parentNode.removeChild(Main)
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
g***@yahoo.com
2006-12-12 15:43:35 UTC
Permalink
Thanks Martin!!

It worked (for appending the document). I've tried several scripts
that I found online and none of them helped. I'm going to test the
removal portion later.

Thanks again!
- Gary
------------------------------------------------------------------------------------------------------------------------------------
Post by Martin Honnen
Post by g***@yahoo.com
<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>
Where is the opening <dataroot> tag?
Post by g***@yahoo.com
I need to append information to this file using ASP. How do I do this?
With classic ASP you use MSXML to load the file, create new elements,
insert them and save the file back e.g.
Dim XmlDoc : Set XmlDoc = CreateObject("Msxml2.DOMDocument.3.0")
XmlDoc.async = False
If XmlDoc.load(Server.MapPath("file.xml")) Then
Dim Main : Set Main = XmlDoc.createElement("MainNode")
Dim Value : Set Value = XmlDoc.createElement("Value")
Value.appendChild(XmlDoc.createTextNode("Fifth Value"))
Main.appendChild(Value)
XmlDoc.documentElement.appendChild(Main)
XmlDoc.Save(Server.MapPath("file.xml"))
Else
' deal with parse error here
End If
Post by g***@yahoo.com
Also, I may need to remove a node from this file ... is that possible?
Find the node using XPath e.g.
XmlDoc.setProperty "SelectionLanguage", "XPath"
Set Main = _
XmlDoc.selectSingleNode("/dataroot/MainNode[Value = 'Third Value']")
then call removeChild e.g.
Main.parentNode.removeChild(Main)
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Loading...