>><?xml version="1.0" standalone="yes" ?> >><Setting> >> <MyElement1>123</MyElement1> >></Setting> >>>>
>LOCAL Source AS String > >* your source document (the contents of your "MyFile.xml") >TEXT TO m.Source NOSHOW ><?xml version="1.0" standalone="yes" ?> ><Setting> > <MyElement1>123</MyElement1> ></Setting> >ENDTEXT > >* what must exist in the document, and the initial value >LOCAL RequiredPath AS String >LOCAL DefaultContent AS String > >m.RequiredPath = "/Setting/MyElement2" >m.DefaultContent = "dummy" > >* our objects to access the DOM >LOCAL XML AS MSXML2.DOMDocument60 >LOCAL Ancestor AS MSXML2.IXMLDOMNode >LOCAL NewElement AS MSXML2.IXMLDOMElement > >m.XML = CREATEOBJECT("MSXML2.DOMDocument.6.0") >m.XML.Async = .F. >m.XML.LoadXML(m.Source) > >* if the required path does not exist... >IF m.XML.Selectnodes(m.RequiredPath).length = 0 > * get what will be its ancestor > m.Ancestor = m.XML.Selectnodes(LEFT(m.RequiredPath, RAT("/", m.RequiredPath) - 1)).item(0) > * create a new element > m.NewElement = m.XML.CreateElement(SUBSTR(m.RequiredPath, RAT("/", m.RequiredPath) + 1)) > * set its value > m.NewElement.text = m.DefaultContent > * and append it to the end of its parent > m.Ancestor.appendChild(m.NewElement) >ENDIF > >* the DOM is reconstructed... >MESSAGEBOX(m.XML.XML) > >* you can save the complete file, just uncomment the next line >* m.XML.Save(GETFILE("xml")) >Hi Antonio,