简体   繁体   English

经典ASP Vbscript中的XML

[英]XML in Classic ASP Vbscript

I am back to asp with XML manupulation. 我回到了XML操纵的asp。 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: 所以我有一个函数: DefinitFunction(x,z)将连接一个字符串,并在DefinitFunction(x,z)附加<Definition> ---<x> </x> <z> </z> --</Definition>最后的Node <sport>应该是我的结果:

<?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? 有没有更好的方法可以做到这一点?

You cannot append text directly .. you need to convert it to XML node first.. 您不能直接附加文本..您需要先将其转换为XML节点。

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

NodeList.appendChild( newXML.documentElement.selectSingleNode("/Definition"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM