Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello !

 

I have a XmlNodeList, which contains some nodes. I would like to "AppendChild" this nodeList to my xml file. But the method AppendChild support only XmlNode.

Is there a way to simply take th nodeList and write it into a file ?

 

Thanks!

Posted

I tried something like that :

 

Dim nodeList as xmlNodeList
Dim fileToChange as new XmlDocument()

fileToChange.Load("file1.xml")
nodeList = fileToChange.selectNodes("rootFloor/floor1/floor2")

Dim i as integer
For i = 0 to nodeList.Count - 1
aNodeWhichHasBeenDeclaredBefore.AppendChild(nodeList.item(i))
next

 

This doesn't work because : "The node to be inserted is from a different document context"

 

I'm not sure, because the "aNodeWhichHasBeenDeclaredBefore" come from a XmlDocument() file, just like fileToChange...So, I don't know...

  • *Experts*
Posted

If it's not from the same XmlDocument object then you'll get that error (I think). Have you tried to clone the node and add it, or maybe use the text of the node and insert that? I'm just throwing out some ideas, I haven't tried to append using the DOM in quite some time.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

Ok, I found a way to manipulate this. Instead of cloning the nodes, I do a selection and import it to my 1st file.

 

file1stFile = New XmlDocument()
...
...
...
fileParam = New XmlDocument()
fileParam.Load(Environment.CurrentDirectory & "\defaut\" & Me.cbChoixParam.SelectedItem)
parameters = fileParam.SelectSingleNode("defaultValues/paramDefault")

param = file1stFile .ImportNode(parameters, True)

game.AppendChild(param)

 

Paramters, param and game are XmlElement.

 

The "fileParam" is the file where I have node to put in my 1st file. The "game" element belong to the first file. With ImportNode, there's no problem of compatibility, but I didn't resolve the problem of the XmlNodeList.

 

Well, it works that way, so it's c:D :D l

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...