Monday 15 March 2010

Keep root element after updating XML from dataset -



Keep root element after updating XML from dataset -

i have written programme update xml file specific values. have run programme , confirmed works except root element. xml file loaded dataset user can update values. after done, new info written new xml file.

the original xml file this:

<dl:xmldatadelivery xsi:schemalocation=http://www.somesite.org/filename.xsd xmlns:dl=http://www.somesite.org/filename xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <partinformation> <partname>hex bolt</partname> <detailedinfo> <partnumber>88-901</partnumber> <serialnumber>sn1234</serialnumber> </detailedinfo> </partinformation> </dl:xmldatadelivery>

however after update xml changes this:

<dl:xmldatadelivery xmlns:dl=http://www.somesite.org/filename> <partinformation> <partname>hex bolt</partname> <detailedinfo> <partnumber>88-901</partnumber> <serialnumber>sn1234</serialnumber> </detailedinfo> </partinformation> </dl:xmldatadelivery>

i've tried several methods add together missing info root element no luck. looked @ changing namespace of dataset allows editing versus adding. tried create new attributes add, have been unsuccessful there too. here's 1 of many things i've tried (note comes after dataset.writexml(filename):

'dim xdoc new xmldocument 'dim ns xmlnamespacemanager 'xdoc.load(newfilestring) 'dim xatt xmlattribute = xdoc.createattribute("xsi:schemalocation") 'xatt.value = "http://www.somesite.org/filename" 'xdoc.attributes.append(xatt) 'ns = new xmlnamespacemanager(xdoc.nametable) 'ns.addnamespace("xsi:schemalocation", "http://www.somesite.org/filename") 'xdoc.save("thisxml.xml")

any help root element original form or edit current 1 great. much all. (let me know if more code needed assess this)

almost forgot provide reply comment (sorry)...

i added next code after dataset update , writexml functions:

dim xdoc new xmldocument dim schemalocation xmlattribute = nil dim schemastring string = "http://www.w3.org/2001/xmlschema-instance" dim schemavalue string = "http://www.somesite.org/filename.xsd" xdoc.load(newfilestring) schemalocation = xdoc.createattribute("xsi", "schemalocation", schemastring) schemalocation.value = schemavalue xdoc.documentelement.setattributenode(schemalocation) xdoc.save(newfilestring)

so root attributes appear as:

<dl:xmldatadelivery xmlns:dl="http://www.somesite.org/filename" xsi:schemalocation="http://www.somesite.org/filename.xsd" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance">

from kennyzx confirmed order not important. mentioned in comments adapted reply provided in msdn forum solve problem.

xml

No comments:

Post a Comment