How to change the nodeType of XML document from DOCUMENT to ELEMENT

StackOverflow https://stackoverflow.com/questions/18241236

  •  24-06-2022
  •  | 
  •  

سؤال

I used XMLDOM to create a document (#1). I used Load("string"). With another XML document (#2), I want to append the first XMLDOM, but I get an error stating "This operation can not be performed with a Node of type DOCUMENT." How can I change the node to type ELEMENT (1)?

oDOM2 = Createobject(MSXML2.DOMDocument)
<bunch of code and other things go here...>

oDOM1 = Createobject(MSXML2.DOMDocument)
oDOM1.Load("<SomeXML><MoreXML></MoreXML></SomeXML>")
oDOM2.appendChild(oDOM1) -->Error

If i use the DOM object to create the object with createElement and addChild, with that fix the problem?

هل كانت مفيدة؟

المحلول

I figured out one way to handle this. After I have completed my document #1, then I can select a single node (the root) into a new DOM object. It works for my purpose.

oDOM2 = Createobject(MSXML2.DOMDocument)
<bunch of code and other things go here...>

oDOM1 = Createobject(MSXML2.DOMDocument)
oDOM1.Load("<SomeXML><MoreXML></MoreXML></SomeXML>")
oDOMTemp = oDOM1.selectSingleNode("//SomeXML")

oDOM2.appendChild(oDOMTemp)

Is there a better way?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top