and everthing else like xsi, gml, xlink declaration are discarded. I want to retain all of them as it was in the souce xml file.
Please tell me how can we retain those tags? Is there any property that needs to be set while calling WriteXML() method? Or is there any other way of doing the same?
jagskadiyala
0 Points
16 Posts
DataSet.WriteXML-Preserve namespace and xsi declaration in root node
Aug 26, 2009 09:55 AM|LINK
Hi,
I am converting xml to dataset and after doing some modifications in it, writing it back as xml using DataSet.WriteXml() method.
Xml snippet:
<ab:nodename xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ab.com/schemas/131 C:\Program Files\AB\RCT\abcd_Composite.xsd" xmlns:ab="http://www.ab.com/schemas/131" xmlns:ns1="http://ab.com/composite.xsd" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink">
But, while writing it back as xml this node written as:
and everthing else like xsi, gml, xlink declaration are discarded. I want to retain all of them as it was in the souce xml file.
Please tell me how can we retain those tags? Is there any property that needs to be set while calling WriteXML() method? Or is there any other way of doing the same?
Thanks and Regards...
Jagadeesh.K.
DataSet.WriteXML XML nodes XML declaration
kavita_khand...
Star
9767 Points
1931 Posts
Re: DataSet.WriteXML-Preserve namespace and xsi declaration in root node
Aug 26, 2009 11:54 AM|LINK
I think after to you receive the xml, you can append these attributes to it like this.
string xml = "<ab:nodename xmlns:ab='http://www.ab.com/schemas/131'/>";
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(xml);
if (xDoc.DocumentElement.Attributes.Count > 0)
{
XmlAttribute xAtt = xDoc.DocumentElement.Attributes[0];
xDoc.DocumentElement.Attributes.Remove(xAtt);
XmlAttribute xAttNs = xDoc.CreateAttribute("xmlns:xsi");
xAttNs.Value = "http://www.w3.org/2001/XMLSchema-instance";
xDoc.DocumentElement.Attributes.Append(xAttNs);
//Such as above, you can keep on adding the attributes you want.
}
//see your resul in following string.
string xmlDoc = xDoc.DocumentElement.OuterXml;
I would love to change the world, but they wont give me the source code.
jagskadiyala
0 Points
16 Posts
Re: DataSet.WriteXML-Preserve namespace and xsi declaration in root node
Aug 26, 2009 12:58 PM|LINK
Just now fixed it by same process....
thanks anyway....