XmlWriter to end of existing Xml doc

  • Thread starter Thread starter Jeroen Ceuppens
  • Start date Start date
J

Jeroen Ceuppens

Hi, I want to add a new node everytime the user clicks savebutton, it adds
information to an existing xml doc, at the end of it

How can I do this?

<?xml version="1.0"?>
<!--Voorgedefinieerde Filters-->
<Filter>
<Node Nr="1">
<Name>EdgeDetect</Name>
<MatrixRij>3</MatrixRij>
<MatrixKolom>3</MatrixKolom>
<MatrixValues>1;1;1;0;0;0;-1;-1;-1</MatrixValues>
<Term>1</Term>
</Node>
<Node Nr="2">
<Name>LowPass</Name>
<MatrixRij>3</MatrixRij>
<MatrixKolom>3</MatrixKolom>
<MatrixValues>1;1;1;1;1;1;1;1;1</MatrixValues>
<Term>1</Term>
</Node>
HERE MUST COME NEW NODE AFTER SAVECLICK>
</Filter>

Greetz
JC
 
Jeroen Ceuppens said:
Hi, I want to add a new node everytime the user clicks savebutton, it adds
information to an existing xml doc, at the end of it

How can I do this?

Do you mean in the file itself? Assuming you've got an in-memory
version already, just append the node at the right place, and then save
the whole thing to disk.

You can't append it at the end of the file itself, because it would be
outside the root element.
 
I have Already the doc loaded in a xmldocument
Jon Skeet said:
Do you mean in the file itself? Assuming you've got an in-memory
version already, just append the node at the right place, and then save
the whole thing to disk.

You can't append it at the end of the file itself, because it would be
outside the root element.
 
Jeroen Ceuppens said:
I have Already the doc loaded in a xmldocument

Okay - so, where do you have a problem? Which bit of what I said can't
you do?
 
Hi I did it like this and it works!

//XmlWriter wr=new XmlWriter();

int hoeveel=this.combobox.Items.Count;

// create XmlNodeReader to access XML document

XmlNodeReader nodeReader = new XmlNodeReader(xmlSourceNode);

XmlNode laatste,toevoeg;

XmlNode[] arnode=new XmlNode[5];

XmlElement nieuw=source.CreateElement("Node");

nieuw.SetAttribute("Nr",(hoeveel+1).ToString());


laatste=xmlSourceNode.LastChild;

laatste.AppendChild(nieuw);

//info uit textboxen halen

MatrixValues=null;

for (int i=0;i<R;i++)

{

for (int j=0;j<K;j++)

{

if(i==R-1 && j==K-1)

MatrixValues=MatrixValues+textBoxMatrix[i,j].Text;

else

MatrixValues=MatrixValues+textBoxMatrix[i,j].Text+";";

}

}

//Verschillende parameters van die node

for (int i=0;i<5;i++)

{

toevoeg=MakePNode(arnode,i);

nieuw.AppendChild(toevoeg);

}


source.Save(@node.headfrm.filterxml);
 
Back
Top