I am trying to create the XML file using the node.js
and npm package xmlbuilder
. When I am trying to create the tags I have some special characters such as : / etc
due to which I am getting the following error:
Error: Invalid character in name: http://google.com.http://google.com
How can I resolve this issue. I can replace it with the blank but I don't want to do that I want my XML to retain these special characters.
var root = builder.create('test:document')
var ObjectEvent = root.ele('ObjectEvent')
for(var ex=0; ex<Extension.length; ex++)
{
Extension[ex].NameSpace = Extension[ex].NameSpace;
Extension[ex].LocalName = Extension[ex].LocalName;
Extension[ex].FreeText = Extension[ex].FreeText;
ObjectEvent.ele(Extension[ex].NameSpace+Extension[ex].LocalName,Extension[ex].FreeText).up()
}
ObjectEvent.ele(Extension[ex].NameSpace+'.'+Extension[ex].LocalName,Extension[ex].FreeText).up()
My Extension
elements would look something like this;
[
{
NameSpace: 'http://google.com',
LocalName: 'http://google.com',
ExtensionVlaues: 0,
FreeText: 'Google Website',
'$$hashKey': 'object:290'
}
]
I wanted to know how can I retain all the special characters in my XML document
XML namespaces can be URIs, but XML element names cannot: /
is not allowed in XML elements names.
I wanted to know how can I retain all the special characters in my XML document
Realize that your error is not about special characters in your XML document; it's about special characters in the names of your XML elements.
Regarding XML elements, you simply must abide by the rules specified in the standard regarding the allowed characters in XML element names. Otherwise, your data is not XML, and you and your callers will not be able to use XML tools and libraries with it.
See also How to include ? and / in XML tag