I'm creating a XML document of registry keys and parameters on VBScript.
Script is working normal, but if the name of the registry key or registry parameter does contain special symbols, like a /
, %
, #
, \\
and other - it causes an error in msxml6.dll
:
This name shouldn't contain a symbol
Code of error: 80004005.
in line 8 of this script:
Dim root, len
Dim rootPath
rootPath = Split(WScript.Arguments(0), "\") 'Registry key
len = UBound(rootPath)
root = rootPath(len)
Set xmlParser = CreateObject("Msxml2.DOMDocument.6.0")
xmlParserAappendChild(xmlParser.CreateProcessingInstruction("xml", "version='1.0' encoding='utf-8'"))
Set rootNode = xmlParser.AppendChild(xmlParser.CreateElement(root))
Set CreateXml = xmlParser
I tryed to find it in Google, but it wasn't successful
How can I fix it?
The characters /
, %
, #
, and \\
aren't valid characters in an XML node name.
From the XML spec :
[...] [4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF] [4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040] [5] Name ::= NameStartChar (NameChar)* [...] [40] STag ::= '<' Name (S Attribute)* S? '>' [WFC: Unique Att Spec] [...]
I'd recommend using generic node names (like <key>
and <value>
) and placinging the key/value names as the value of an attribute name
of those nodes. Example:
Set xml = CreateObject("Msxml2.DOMDocument.6.0")
Set node = xml.CreateElement("key")
node.SetAttribute("name") = "foo%bar"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.