Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: How do I insert a node into a xml document? >Thread Next - Re: How do I insert a node into a xml document? Re: How do I insert a node into a xml document?To: NULL Date: 11/3/2004 12:48:00 AM Thanks for this.
As soon as I added the "DocumentElement" section in, it worked..!
e.g
call MyDocument.InsertBefore(oNewNode,oPosition) => does not work
call MyDocument.DocumentElement.InsertBefore(oNewNode,oPosition) => works!
"Gadrin77" wrote:
> I'm using MS XML 4.0, I'm not using VB (but it's very similar) so no
> "Set" command is needed...
>
>
> xmlDoc = ObjectOpen("Msxml2.DOMDocument.4.0")
> xmlDoc.async = @False
> xmlDoc.loadxml("<Book><Author>TJones</Author><Title>My
> Book</Title></Book>")
>
> DaNode = xmlDoc.selectSingleNode("//Book/Title") ;<-- choose the node
> AFTER the Author...
> newElement = xmlDoc.createElement("Subject")
> ; assign the new element a value...
> newElement.text = "The Subject"
> ; append it to the document...
> xmlDoc.documentElement.insertBefore(newElement, DaNode)
>
> message("Debug", xmlDoc.xml)
>
> exit
>
> If <Book> isn't your root you can adjust the Xpath to locate it and
> also the
> line with .documentElement.
>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
