Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. DataSet.WriteXml Problem With Nested Elements Of Same Name

DataSet.WriteXml Problem With Nested Elements Of Same Name

Scheduled Pinned Locked Moved ASP.NET
questionadoberegexxmlhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stephen Adam
    wrote on last edited by
    #1

    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

    N 1 Reply Last reply
    0
    • S Stephen Adam

      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

      N Offline
      N Offline
      NewSilence
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups