Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey,

I have this Xml code :

XML
<pre><?xml version="1.0" encoding="UTF-8"?>
<PARAMETRE>
    <PARAMETRE_ITEM>
        <key>13042023</key>
        <value>10</value>
        <unit>mètres</unit>
        <name>Ceci est une description pour le paramètre 1.</name>
    </PARAMETRE_ITEM>
    <PARAMETRE_ITEM>
        <key>14042023</key>
        <value>5</value>
        <unit>secondes</unit>
        <name>Ceci est une description pour le paramètre 2.</name>
    </PARAMETRE_ITEM>
    <PARAMETRE_ITEM>
        <key>15042023</key>
        <value>3.14</value>
        <unit>degrés</unit>
        <name>Ceci est une description pour le paramètre 3.</name>
    </PARAMETRE_ITEM>
</PARAMETRE>


And I want to do create a script VBNET in order to add new data with a key, value, unit and name.

What I have tried:

dim parametre as System.Xml.XmlDocument;
parametre = new System.Xml.XmlDocument;
parametre.Load("c:\Test.xml");


dim catalog as System.Xml.XmlElement;
catalog.SetAttribute("1", "0385503822");
catalog.InnerText="Test";
catalog.AppendChild(catalog);


' save the XML document to disk
parametre.Save("c:\Test.xml");
Posted
Updated 13-Apr-23 23:21pm
v2

1 solution

VB
catalog.AppendChild(catalog);
How do you expect that to work?
It appends the node to itself as a child node!
Even if it worked, when you tried to write it to a file, it would loop infinitely trying to get to the end of the children ...

Did you mean to add it to the parametre instead?
 
Share this answer
 
Comments
Richard Deeming 14-Apr-23 5:26am    
It won't even get that far - catalog is never assigned a value, so the catalog.SetAttribute call will throw a NullReferenceException. :)
OriginalGriff 14-Apr-23 6:07am    
That's why "Even if it worked" :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900