2

I am back to asp with XML manupulation. Initial file:

<?xml version="1.0" ?>
<root>
  <sport/>
</root>

this is my function

Public Function DefinitFunction( x,z)


Dim text 
Dim Root
Dim NodeList

    text = "<Definition>" ---<x> </x> <z> </z> --</Definition> " 
    text = text & "<x><![CDATA["&x&"]]> </x>"
    text = text & "<z> </z>"        
    text = text & "</Definition>"

Set Root = objDoc.documentElement 
Set NodeList = Root.getElementsByTagName("sport") 

NodeList.appendChild text 

objDoc.Save strFile

end function
'  Private strFile, objDoc are class object

I want to modify the all thing dynamically. So I have a function : DefinitFunction(x,z) that will concatenate a string and append <Definition> ---<x> </x> <z> </z> --</Definition> in my file right after the Node <sport> at the end this should be my result:

<?xml version="1.0" ?>
<root>
  <sport>
    <Definition>
        ---<x> </x> <z> </z> --
      </Definition> 
   </sport>
</root>

This is not working. Is there any better way of accomplishing this?

1
  • Its not entirely clear from your code sample, but are you using the MSXML object or something else? Commented Feb 13, 2010 at 20:24

1 Answer 1

2

You cannot append text directly .. you need to convert it to XML node first..

Set newXML = CreateObject("Microsoft.XMLDOM") 
newXML.async = False 
newXML.loadXML( "<root>" & text & "</root>")

NodeList.appendChild( newXML.documentElement.selectSingleNode("/Definition"))
Sign up to request clarification or add additional context in comments.

5 Comments

Nope Error Type: Microsoft VBScript runtime (0x800A01B6) Object doesn't support this property or method: 'NodeList.appendChild'
do not use Root.getElementsByTagName("sport") to get to sport.. use Root.selectSingleNode("sport"). The first returns a node list (to which you cannot append directly) the second returns a node (which supports the appendChild..)
This is a plus.thanks. However it append outside of the sport node <sport> </sport> <Definition> ---<x> </x> <z> </z> -- </Definition> instead of <sport> <Definition> ---<x> </x> <z> </z> -- </Definition> </sport>
All good. my bad It all good Thanks for your help from the future expert in xml -asp
no problem ZAfrican .. have fun with xml ;) (you should go back to your questions and accept answers if they were helpful .. this will make people more eager to answer your future questions..)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.