tags:

views:

218

answers:

1

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 dinamically. 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 ? thanks for ur help

+1  A: 

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"))
Gaby
NopeError Type:Microsoft VBScript runtime (0x800A01B6)Object doesn't support this property or method: 'NodeList.appendChild'
FasoService
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..*)
Gaby
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>
FasoService
All good. my badIt all good Thanks for your help from the future expert in xml -asp
FasoService
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..*)
Gaby