-
Generating XML
Hi
This is a weird one. I'm using a reference to msxml3.dll and the following code to generate an xml file:
Code:
'Create "message" node
Set xmln_message = xmlDoc.createNode(XMLELEMTYPE_TEXT, "message", "")
xmlDoc.appendChild xmln_message
Set xmlAttribute = xmlDoc.createAttribute("xmlns")
xmlAttribute.Value = "http://www.origoservices.com"
xmln_message.Attributes.setNamedItem xmlAttribute
Set xmlAttribute = xmlDoc.createAttribute("xmlns:fp")
xmlAttribute.Value = "http://www.friendsprovident.com"
xmln_message.Attributes.setNamedItem xmlAttribute
Set xmlAttribute = xmlDoc.createAttribute("xmlns:origo")
xmlAttribute.Value = "http://www.origoservices.com"
xmln_message.Attributes.setNamedItem xmlAttribute
Set xmlAttribute = xmlDoc.createAttribute("xmlns:x")
xmlAttribute.Value = "http://www.origoservices.com"
xmln_message.Attributes.setNamedItem xmlAttribute
Set xmlAttribute = xmlDoc.createAttribute("xmlns:xsi")
xmlAttribute.Value = "http://www.w3.org/2001/XMLSchema-instance"
xmln_message.Attributes.setNamedItem xmlAttribute
'Create "m_control" node
Set xmln_mcontrol = xmlDoc.createNode(XMLELEMTYPE_TEXT, "m_control", "")
xmln_message.appendChild xmln_mcontrol
...etc etc to create the other nodes in the page
all the objects have been properly instantiated etc and all the nodes with child nodes have their own object variable. The problem is that the "xmlns" attribute although only added to the "message" node, appears on all of the child nodes of "message" as well, im currently using a workaround by using a replace function on the generated xml to remove the unneeded "xmlns" attributes but obviously i would prefer to avoid it happening at all. Strangely it does not do the same with the other attributes of the "message" node. any help would be much appreciated with this one!
-
Re: Generating XML
-
Re: Generating XML
Please don't bump your threads.
When I use that xml code I get a file that looks like this
<message xmlns="http://www.origoservices.com" xmlns:fp="http://www.friendsprovident.com" xmlns:origo="http://www.origoservices.com" xmlns:x="http://www.origoservices.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><m_control xmlns=""/></message>
Is it the xmlns part like the highlighted one that you don't want? If so then just change your CreateAttribute statements form, for example
xmlDoc.createAttribute("xmlns:fp")
to
xmlDoc.createAttribute("fp")
-
Re: Generating XML
My apologies for the bump, but no, when i create nodes as childnodes of "message" they have a blank attribute so they appear as:
<childnode xmlns="">
stuff
</childnode>
as you can see on your post on the mcontrol node
-
Re: Generating XML
If I understand correctly what you want, it's because you aren't adding a value. In this case I've added "blah"
Set xmln_mcontrol = xmlDoc.createNode(XMLELEMTYPE_TEXT, "m_control", "blah")