Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to add new elements to xml file
Message
De
12/06/2008 12:54:06
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
XML, XSD
Titre:
How to add new elements to xml file
Divers
Thread ID:
01323532
Message ID:
01323532
Vues:
57
Using Createobject("MsXml2.DomDocument") I can create the following xml file:
<?xml version="1.0" encoding="UTF-16"?>
<settings>
	<node1>
		<field1>data11</field1>
		<field2>data12</field2>
		<field3>data13</field3>
		<subnode1>
			<field1>data111</field1>
			<field2>data112</field2>
			<field3>data113</field3>
		</subnode1>
	</node1>
	<node2>
		<field1>data21</field1>
		<field2>data22</field2>
		<field3>data23</field3>
		<subnode2>
			<field1>data221</field1>
			<field2>data222</field2>
			<field3>data223</field3>
		</subnode2>
	</node2>
</settings>
I don´t have any problems getting and setting the values of each existing element using SelectSingleNode, I have a method to get a value:
GetValue("node2\subnode2\field2", "defaultvalue")
If the node is not found, "defaultvalue" is returned. And to set a value:
SetValue("node2\subnode2\field2", "value")
The problem is that when setting a value, if the node does not exist, I want to add it and then set the value, for example:
SetValue("node2\subnode2\field4", "value")
Should add an element field4 in node2 - subnode2. How do I do that? I am using "\" in the method call, those get replaced by "/" in the method so xpath works.
The whole idea is to add an alternative to my registry class, so settings can be stored in an xml file instead of the registry.

Carlos Alloatti
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform