DataSet.WriteXml Problem With Nested Elements Of Same Name
-
Hi there, I've got a problem with the DataSet.WriteXml method. I has an xml document which describes regions down to any level so for instance we might have something like this. > My problem is when I use the DataSet.WriteXml the elements are named based on the table names, now this isnt such a huge problem because I can just give them aliases like so... myDataSet.Tables["World"].TableName = "region"; myDataSet.Tables["Regions"].TableName = "region"; myDataSet.Tables["Countries"].TableName = "region"; But now I get a complaint from the dataset that I cant have two tables of the same name, how can I tell the WriteXML method or the dataset what to name the element tags? My only hack that i've thought of so far is this... myDataSet.Tables["World"].TableName = "region"; myDataSet.Tables["Regions"].TableName = "rEgion"; myDataSet.Tables["Countries"].TableName = "reGion"; and then to get rid of the element upper case with a regex as it comes out of the XmlTextWriter. How nasty is that? Tricking it using the same name in a different case. There must be a better way and microsoft cant have been so sort sighted. Cant they?? Nested elements of the same type, its not that crazy ass is it? Cheers for having a look! Steve protected void GetDealerInformation() { mySqlConnection.Open(); myDataSet.Clear(); mySqlDataAdapter = new SqlDataAdapter("SELECT * FROM tblWorld; SELECT * FROM tblRegions; SELECT * FROM tblCountries; SELECT * FROM tblDealers", mySqlConnection); mySqlConnection.Close(); mySqlDataAdapter.TableMappings.Add("Table", "World"); mySqlDataAdapter.TableMappings.Add("Table1", "Regions"); mySqlDataAdapter.TableMappings.Add("Table2", "Countries"); mySqlDataAdapter.TableMappings.Add("Table3", "Dealers"); mySqlDataAdapter.Fill(myDataSet); } protected void UpdateXMLFile () { GetDealerInformation(); string strPath = Request.PhysicalApplicationPath + @"Flash\locator13.xml"; XmlTextWriter myXmlTextWriter = new XmlTextWriter(strPath, Encoding.UTF8); myXmlTextWriter.Formatting = System.Xml.Formatting.Indented; DataRelation myDataRelation; DataColumn myParentCol; DataColumn myChildCol; myParentCol = myDataSet.Ta
-
Hi there, I've got a problem with the DataSet.WriteXml method. I has an xml document which describes regions down to any level so for instance we might have something like this. > My problem is when I use the DataSet.WriteXml the elements are named based on the table names, now this isnt such a huge problem because I can just give them aliases like so... myDataSet.Tables["World"].TableName = "region"; myDataSet.Tables["Regions"].TableName = "region"; myDataSet.Tables["Countries"].TableName = "region"; But now I get a complaint from the dataset that I cant have two tables of the same name, how can I tell the WriteXML method or the dataset what to name the element tags? My only hack that i've thought of so far is this... myDataSet.Tables["World"].TableName = "region"; myDataSet.Tables["Regions"].TableName = "rEgion"; myDataSet.Tables["Countries"].TableName = "reGion"; and then to get rid of the element upper case with a regex as it comes out of the XmlTextWriter. How nasty is that? Tricking it using the same name in a different case. There must be a better way and microsoft cant have been so sort sighted. Cant they?? Nested elements of the same type, its not that crazy ass is it? Cheers for having a look! Steve protected void GetDealerInformation() { mySqlConnection.Open(); myDataSet.Clear(); mySqlDataAdapter = new SqlDataAdapter("SELECT * FROM tblWorld; SELECT * FROM tblRegions; SELECT * FROM tblCountries; SELECT * FROM tblDealers", mySqlConnection); mySqlConnection.Close(); mySqlDataAdapter.TableMappings.Add("Table", "World"); mySqlDataAdapter.TableMappings.Add("Table1", "Regions"); mySqlDataAdapter.TableMappings.Add("Table2", "Countries"); mySqlDataAdapter.TableMappings.Add("Table3", "Dealers"); mySqlDataAdapter.Fill(myDataSet); } protected void UpdateXMLFile () { GetDealerInformation(); string strPath = Request.PhysicalApplicationPath + @"Flash\locator13.xml"; XmlTextWriter myXmlTextWriter = new XmlTextWriter(strPath, Encoding.UTF8); myXmlTextWriter.Formatting = System.Xml.Formatting.Indented; DataRelation myDataRelation; DataColumn myParentCol; DataColumn myChildCol; myParentCol = myDataSet.Ta
try to use qualified names.
<root xmlns:s1="blahblah1" xmlns:s2="blahblah2"> <s1:reg> <s2:reg></s2:reg> </s1:reg> </root>
why don't to use XSDs and strong typed datasets?. I think that prevents such errors