Altova Mailing List Archives


Re: .replceChild problem

From: "Joe Fawcett" <joefawcett@-------.--->
To: NULL
Date: 3/5/2004 4:55:00 PM
Sorry that last one was abit garbled due to my inept typing skills. Let me
know if you have any problems understanding it.

Have a good weekend.

Joe

"Joe Fawcett" <joefawcett@h...> wrote in message
news:%233Z$uItAEHA.1732@T......
> "Navin Kumar" <itsnavin@y...> wrote in message
> news:89580c73.0403050831.1e5ef681@p......
> > I am trying to change existing XML with new XML with replaceChild()
> > method:
> > Here is old XML:
> > <codes_list>
> >  <list name="AIS_LISTITEMS" area="AIS">
> > <item code="AIS" desc="Some Description"/>
> > <item code="ALLIANCE" desc="Some other"/>
> > <item code="AIR" desc="More desc"/>
> > <item code="APT" desc="I have some more"/>
> > <item code="AIM" desc="last desc"/>
> >  </list>
> >  ...
> > </codes_list>
> >
> > New XML:
> > <list name="AIS_LISTITEMS" area="AIS">
> > <item code="AZZ" desc="Some Description"/>
> > <item code="ALL" desc="Some other"/>
> > <item code="APR" desc="More desc"/>
> > <item code="YYY" desc="I have some more"/>
> > <item code="ZZZ" desc="last desc"/>
> >  </list>
> >
> > And I want to replace the whole of the list named "AIS_LISTITEMS" in
> > the oldXML with the new XML.
> > What I am doing is something like this:
> >
> > var newDOM = new ActiveXObject("MSXML2.DOMDocument.4.0");
> > newDOM.async = false;
> > newDOM.loadXML(newXML)
> > var newChild = newDOM.selectSingleNode("//list")
> >
> > var oldDOM = new ActiveXObject("MSXML2.DOMDocument.4.0");
> > oldDOM.async = false;
> > oldDOM.loadXML(OldXml)
> > var oldChild = objXML.selectSingleNode("//list[@name='REQTYPE']")
> >
> > var temp =
> objXML.documentElement.childNodes.item(1).replaceChild(newChild,
> > oldChild);
> >
> > 'temp' should give me the replaced node but instead it gives me error
> > as "Insert position Node must be a Child of the Node to insert under."
> >
> > Could any one let me know what wrong with my code and how to correct
> > it as well
> > Thanks a lot.
> > Navin Kumar
> I believe there are a couple of errors, items collection is zero based and
> you can't directly move nodes from one document to another. You are also
> using an over exuberant search, you don't need // at the front of the
xpath
> you need to use cloneNode which is msxml parser's version of what should
be
> importNode. It's easier in this situation to use the child to replace
itself
> as in:
>
> var newChild = newDOM.selectSingleNode("list").cloneNode(true);
>
> var oldChild = objXML.selectSingleNode("//list[@name='REQTYPE']");  //Is
> "REQTYPE" correct, not "AIS_LISTITEMS"?
>
> var temp = oldChild.parentNode.replaceChild(newChild, oldChild);
>
> Hope this helps
>
> -- 
>
> Joe (MVP - xml)
>
>
>


Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.