Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello!

 

I need some help to use the method ReplaceChild. What I know is the structure of it.

 

domDoc.ReplaceChild( newChild, oldChild )

 

The problem I have is that the new child is not from the same dom document as the old child. The thing is, I don't understand why the two of them must be from the same file.

 

It's not very logical...:confused: I mean, I have a node in a document. If I want to replace it, the new node will be *in any case* a node that is not in the file, I think...

 

Well, I'm a bit confused about that. But I abolutely need this method, and I can't have the two nodes coming from the same document, sob...

 

If someone has an idea...thanks a LOT !

Posted

Here's a part of my code...The error is : "The node to be removed is not a child of this node"...

       Dim fDom As New XmlDocument
       fDom.Load(Me.fileName)
       Dim paramDefault As XmlElement
       Dim oldParam As XmlNode

       'This method returns a XmlElement type. It puts in paramDefault some children and some values. The fDom is passed by reference.
       paramDefault = Me.SetParamDefault(fDom)
       'Then we select the old node from the document. Game is the root element.
       oldParam = fDom.SelectSingleNode("game/paramDefault")
       'Here's the error...
       fDom.ReplaceChild(paramDefault, oldParam)
       fDom.Save(fichierTemp)

 

I use the SetParamDefault method in other method and function in my class, and it works perfectely...

 

Maybe I'm wrong, but it seems everything 's right..

  • *Experts*
Posted

I believe I see the problem. The only child node of fDom is the

"game" node; thus, the "game/paramDefault" node is not a child

of the fDom document, it's a child of the "game" node. You need

to call the ReplaceChild of the "game" node instead of the

ReplaceChild method of the main document.

 

'Here's the error...
fDom.SelectSingleNode("game").ReplaceChild(paramDefault, oldParam)

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...