Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding XML attributes to an Element with WriteXML

Status
Not open for further replies.

pabowen

Programmer
Nov 6, 2002
95
US
Hello everyone,

I am writing out a file from a dataset using WriteXML. However, I need to add attributes to a couple of elements. How can I add an attribute to the elements? I can either hardcode the attributes, or put them in the result set, or dataset name.

My code looks like this.
Code:
DataSet myDataSet = new DataSet("COURSE_MASTER");
myConnection.Open();
mySqlDataAdapter.Fill(myDataSet,"Row" );
myDataSet.WriteXml(Server.MapPath("XMLTest.XML"));

This is producing xml that looks like this: (Note that the <COURSE_MASTER> tag has a bunch of attributes, and that Type is moved from an element to being an attribute or <Row>

<?xml version="1.0" standalone="yes" ?>
- <COURSE_MASTER>
- <Row>
<Type>U</Type>
<CSE_NB>AA110LOCAL</CSE_NB>
<CSE_NM>110 Local</CSE_NM>
<CSE_DS>description test</CSE_DS>
<CSE_HR>1.0000000000</CSE_HR>
<LMS_UPDT_DT>2006-05-09</LMS_UPDT_DT>
</Row>
</COURSE_MASTER>

I need it to look something like this.

<?xml version="1.0" standalone="yes" ?>
- <TRAINING_COURSE_MASTER xmlns:xsi=" xmlns="urn:com.cust.top.test.course_master"
xsi:schemaLocation="urn:com.cust.top.test.course_master course_master.xsd">
- <Row type="U">
<CSE_NB>AA110LOCAL</CSE_NB>
<CSE_NM>110 Local</CSE_NM>
<CSE_DS>description test</CSE_DS>
<CSE_HR>1.0000000000</CSE_HR>
<LMS_UPDT_DT>2006-05-09</LMS_UPDT_DT>
</Row>

Any Help with this would be greatly appreciated.
Thanks,
Patrick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top