The following code snippet returns xml document
public XmlDocument GetXMLFile(int ID)
{
List<UserInfoBE> data = GetById(ID);
DataSet ds = ConvertGenericsListToDataSet(data);
XmlDocument XmlDoc = new XmlDocument();
XmlDocument doc = GenerateXMLDeclaration(XmlDoc);//Create xml Declaration
doc = AddTableTag(doc);//Create parent node USERDATA
foreach (DataRow dr in ds.Tables[0].Rows)
{
doc = AddUserinfoTag(doc, dr[8].ToString(), Convert.ToInt32(dr[31].ToString()), Convert.ToString(dr[32].ToString()), dr[3].ToString());
}
doc = SetHeirarchyLevel(doc);
string _errorFile = AppDomain.CurrentDomain.BaseDirectory + "XML\\";
System.IO.Directory.CreateDirectory(_errorFile);
_errorFile += "FIle" + DateTime.Now.ToString("dd-MM-yyyy") + ".xml";
XmlNodeList nodes = doc.SelectNodes("USERDATA/Userinfo");
XmlDocument newXMLDoc = new XmlDocument();
XmlDocument newDoc = GenerateXMLDeclaration(newXMLDoc);
newDoc.AppendChild(nodes);
doc.Save(_errorFile);
return doc;
}
XML file format:
<?xml version="1.0"?>
<USERDATA>
<Userinfo>
<Userinfo>
<Userinfo>
<Userinfo>
<Userinfo>
<Userinfo/>
<Userinfo>
<Userinfo/>
</Userinfo>
</Userinfo>
<Userinfo>
<Userinfo/>
<Userinfo/>
</Userinfo>
</Userinfo>
</Userinfo>
</Userinfo>
</Userinfo>
</EDVDATA>
Question how do get file in following format
<Userinfo>
<Userinfo>
<Userinfo>
<Userinfo>
<Userinfo>
<Userinfo/>
<Userinfo>
<Userinfo/>
</Userinfo>
</Userinfo>
<Userinfo>
<Userinfo/>
<Userinfo/>
</Userinfo>
</Userinfo>
</Userinfo>
</Userinfo>
</Userinfo>
What i have tried is saving the return doc object (Xml file) in a folder.
then created a new xmldocument object and trying to append Xmlnodelist which userinfo structure(just above) in new xmlobject
newDoc.AppendChild(nodes); line throws an error
cannot convert from ‘System.Xml.XmlNodeList’ to ‘System.Xml.XmlNode’
any help is very much appreciated.
You are trying to append multiple nodes but the function takes single node to append at a time. Try this: