Answered by:
DataSet to XMLDocument

Question
-
User2043281626 posted
Hello,
I am trying to obtain a XmlNodeList from a XMLDocument that originally started off as a DataSet, but everytime I do so I get a ZERO count of rows. I know that there are at least a few rows being returned, so I am not sure what I am doing wrong here. Before when this functionality used to be SQLXML there was no problem obtaining a XmlNodeList and the data. see below for how the data looks in the xml document:
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
<exam>
<UniqueNumber>32q452345</UniqueNumber>
<lQuestionID>wweer322twatew7</lQuestionID>
<SuperDate>8/14/2012</SuperDate>
<FinalDate>8/20/2012</FinalDate>
<Status>Final</Status>
<Source>MyDataSource</Source>
</exams>
</exam>
</string>Any clues as to what is going on?
Monday, August 12, 2013 3:50 PM
Answers
-
User260886948 posted
Hi,
I do not know if I misunderstand your idea, and I have created the following code to convert the dataset to xmldocument, please try to refer to:protected void Page_Load(object sender, EventArgs e) { DataSet ds = new DataSet("string"); ds.Namespace = "http://schemas.microsoft.com/2003/10/Serialization/"; DataTable stdTable = new DataTable("exam"); DataColumn col1 = new DataColumn("UniqueNumber"); DataColumn col2 = new DataColumn("IQuestionID"); DataColumn col3 = new DataColumn("SuperDate"); DataColumn col4 = new DataColumn("FinalDate"); DataColumn col5 = new DataColumn("Status"); DataColumn col6 = new DataColumn("Source"); stdTable.Columns.Add(col1); stdTable.Columns.Add(col2); stdTable.Columns.Add(col3); stdTable.Columns.Add(col4); stdTable.Columns.Add(col5); stdTable.Columns.Add(col6); ds.Tables.Add(stdTable); DataRow newRow; newRow = stdTable.NewRow(); newRow["UniqueNumber"] = "32q452345"; newRow["IQuestionID"] = "wweer322twatew"; newRow["SuperDate"] = "8/14/2012"; newRow["FinalDate"] = "8/20/2012"; newRow["Status"] = "Final"; newRow["Source"] = "MyDataSource"; stdTable.Rows.Add(newRow); ds.AcceptChanges(); StreamWriter myStreamWriter = new StreamWriter(Server.MapPath("asp.xml")); ds.WriteXml(myStreamWriter); myStreamWriter.Close(); }
The result:
Best Regards.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, August 16, 2013 5:27 AM
All replies
-
User2043281626 posted
If it helps, I guess part of the issue is that I am trying to obtain the same formatting as SQLXML; "xmlns:sql=\"urn:schemas-microsoft-com:xml-sql"
Anyone have any ideas? I was expecting to get some feedback on this one lol
I would like to add that the XMLDocument returned to a calling web application from a REST Service. Not sure if this makes a difference or not. Can someone please help me with this issue!
Tuesday, August 13, 2013 7:55 AM -
User260886948 posted
Hi,
I do not know if I misunderstand your idea, and I have created the following code to convert the dataset to xmldocument, please try to refer to:protected void Page_Load(object sender, EventArgs e) { DataSet ds = new DataSet("string"); ds.Namespace = "http://schemas.microsoft.com/2003/10/Serialization/"; DataTable stdTable = new DataTable("exam"); DataColumn col1 = new DataColumn("UniqueNumber"); DataColumn col2 = new DataColumn("IQuestionID"); DataColumn col3 = new DataColumn("SuperDate"); DataColumn col4 = new DataColumn("FinalDate"); DataColumn col5 = new DataColumn("Status"); DataColumn col6 = new DataColumn("Source"); stdTable.Columns.Add(col1); stdTable.Columns.Add(col2); stdTable.Columns.Add(col3); stdTable.Columns.Add(col4); stdTable.Columns.Add(col5); stdTable.Columns.Add(col6); ds.Tables.Add(stdTable); DataRow newRow; newRow = stdTable.NewRow(); newRow["UniqueNumber"] = "32q452345"; newRow["IQuestionID"] = "wweer322twatew"; newRow["SuperDate"] = "8/14/2012"; newRow["FinalDate"] = "8/20/2012"; newRow["Status"] = "Final"; newRow["Source"] = "MyDataSource"; stdTable.Rows.Add(newRow); ds.AcceptChanges(); StreamWriter myStreamWriter = new StreamWriter(Server.MapPath("asp.xml")); ds.WriteXml(myStreamWriter); myStreamWriter.Close(); }
The result:
Best Regards.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, August 16, 2013 5:27 AM