problem with insertBefore method

problem with insertBefore method

Post by Toby Mathew » Thu, 15 Aug 2002 00:20:33



Hi there,

  I'm new to XML and struggling! I'm trying to add a new node to an XML
document using client JS (running on IE6). The code looks like this:

XMLDoc = new ActiveXObject("Microsoft.XMLDOM");
XMLDoc.async = false;
XMLDoc.load("XMLDocument.xml");

newEl = XMLDoc.createElement("HLP");
newEl.setAttribute("text",document.all["thing"].value)

ContainerElement = XMLDoc.firstChild;

ContainerElement.insertBefore(newEl,
ContainerElement.childNodes[document.all["Position"].value]);

'Position' (from my web page) is 0, 'thing' is just some text.When I try to
execute this code I get "The operation can not be performed with a Node of
type ELEMENT" when it tries to perform the insertBefore line. Does anyone
have any idea why this might be happening? Thanks in advance for any help,
it's much appreciated.

Toby Mathews

 
 
 

problem with insertBefore method

Post by Han » Sun, 18 Aug 2002 13:41:47


Toby.

What is /document/ which appears twice in your code? If I delete the
mysterious object, it works.

set XMLDoc =createobject("Msxml2.domdocument")
XMLDoc.async = false
XMLDoc.load "X.xml"

set newEl = XMLDoc.createElement("HLP")
newEl.setAttribute "text","something"

set ContainerElement = XMLDoc.firstChild

ContainerElement.insertBefore newEl,ContainerElement.childNodes(1)

xmldoc.save "x.xml"

I changed your code into vbs with which I'm comfortable.

--
Han Pohwan, Seoul/Korea, Microsoft MVP


Quote:> Hi there,

>   I'm new to XML and struggling! I'm trying to add a new node to an XML
> document using client JS (running on IE6). The code looks like this:

> XMLDoc = new ActiveXObject("Microsoft.XMLDOM");
> XMLDoc.async = false;
> XMLDoc.load("XMLDocument.xml");

> newEl = XMLDoc.createElement("HLP");
> newEl.setAttribute("text",document.all["thing"].value)

> ContainerElement = XMLDoc.firstChild;

> ContainerElement.insertBefore(newEl,
> ContainerElement.childNodes[document.all["Position"].value]);

> 'Position' (from my web page) is 0, 'thing' is just some text.When I try
to
> execute this code I get "The operation can not be performed with a Node of
> type ELEMENT" when it tries to perform the insertBefore line. Does anyone
> have any idea why this might be happening? Thanks in advance for any help,
> it's much appreciated.

> Toby Mathews


 
 
 

problem with insertBefore method

Post by Han » Sun, 18 Aug 2002 17:05:49


Toby

Your code has no problem except the /document ~/ parts which appear twice.
Try with "thing" and 0 instead of the /document ~/ parts.

--
Han Pohwan, Seoul/Korea, Microsoft MVP


Quote:> Hi there,

>   I'm new to XML and struggling! I'm trying to add a new node to an XML
> document using client JS (running on IE6). The code looks like this:

> XMLDoc = new ActiveXObject("Microsoft.XMLDOM");
> XMLDoc.async = false;
> XMLDoc.load("XMLDocument.xml");

> newEl = XMLDoc.createElement("HLP");
> newEl.setAttribute("text",document.all["thing"].value)

> ContainerElement = XMLDoc.firstChild;

> ContainerElement.insertBefore(newEl,
> ContainerElement.childNodes[document.all["Position"].value]);

> 'Position' (from my web page) is 0, 'thing' is just some text.When I try
to
> execute this code I get "The operation can not be performed with a Node of
> type ELEMENT" when it tries to perform the insertBefore line. Does anyone
> have any idea why this might be happening? Thanks in advance for any help,
> it's much appreciated.

> Toby Mathews

 
 
 

1. Xereces insertBefore method

Hi all,
        apologies if this has been raised before or if this is the incorrect forum, but I am
going slightly nuts trying to get the insertBefore method to work.  When I put it in my code it
compiles fine, however I am getting a runtime error of

DOM008 Not Found

What i'm doing is creating an element then I want to insert it into the XML file before a
particular element.  I search for this lement, get it then use the insertBefore method and I get
the above error message.  I would include some code but because i've tried it about 62,000
different ways i've got myself slightly confused.

Any help greately appreciated,

Pete
--
-------------------------------------------------------------------------
Pete Wilkins                        3rd Year Software Engineering (RMIT)  


2. Blockparty 2010 Awards Ceremony video

3. Calling insertBefore method from ATL COM

4. Policies

5. How to set refChild in insertBefore method in C++

6. Help with connecting to Exchange Server

7. How to use InsertBefore() Method?

8. 3Com OfficeConnect 802.11g

9. Using insertBefore Method in MSXML

10. Using InsertBefore method of MSXML

11. insertBefore problem

12. insertBefore problems

13. InsertBefore problem