AllExperts > Experts 
Search      

XML

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More XML Answers
Question Library

Ask a question about XML
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Ashvin
Expertise
I can handle all the queries related to XML. I can sort out problems regarding XSLT and XSL. I work using MSXML components. I can handle XML-SQl, XML-VB and XMl-ASP related queries.

Experience
I have worked for 2years in this feild. I have worked in SGML and DTDs, and now working in XML and Schemas.

 
   

You are here:  Experts > Computing/Technology > HTML/XML > XML > adding an element

Topic: XML



Expert: Ashvin
Date: 3/31/2004
Subject: adding an element

Question
-------------------------
Followup To
Question -
I an getting data from a database in XML form.  It looks like this:

<NewDataSet>
 <Table1></Table1>
 <Table2></Table2>
</NewDataSet>

Every query comes back like this.  Each time I update the XML it does so like this:

<NewDataSet>
 <Table1></Table1>
 <Table2></Table2>
 <Table1></Table1>
 <Table2></Table2>
</NewDataSet>

I would like it to reform the XML data with a schema.  I would like the data to look like this:

<NewDataSet>
 <Query>
   <Table1></Table1>
   <Table2></Table2>
 </Query>
 <Query>
   <Table1></Table1>
   <Table2></Table2>
 </Query>
</NewDataSet>

Is this possible?  If so, how?
Answer -
Hello Don,

I have gone through your code, I am not able to understand how you are getting your XML from the database. I mean to say which language you used for the XML output. It can be done with SQL Query itself and also by using some scripting language. So it will be good if you send me the remaining code for retrinving XML for the Database. I can help you in better way.

Thanks for asking

Take care

I'm using VB.Net for my application.  Here is my basic code:

       Dim strConnectionString As String = "My database connection"
       Dim strQuery As String = "execute sp_StoredProcedure"
       Dim myDataset As DataSet = New DataSet
       Dim mySqlConnection As New SqlConnection(strConnectionString)
       Dim mySqlDataAdapter As New SqlDataAdapter

       'Get query results
       mySqlDataAdapter.SelectCommand = New SqlCommand(strQuery, mySqlConnection)
       mySqlDataAdapter.Fill(myDataset)
       myDataset.WriteXML("Results.xsl")

Basically I create a dataset, call a stored procedure and fill the dataset with the results.  I just call 'myDataset.WriteXML("Results.xsl")' and .Net does the rest.  Does this help?

Answer
Hi Don,

You can get XML as per your requirement.

I have tried your code and get the value in same structure what you are asking for with your same code only.

<!-- My out put-->

<NewDataSet>
<Table>
 <donatID>2</donatID>
 <regUserID>1</regUserID>
 <donationFor>1</donationFor>
 <drawe_bank>icici</drawe_bank>
</Table>
<Table>
 <donatID>3</donatID>
 <regUserID>1</regUserID>
 <donationFor>1</donationFor>
 <drawe_bank />
</Table>
</NewDataSet>

I think you must chek you table columns. And also you are creating XML file so mention XML in the  --[myDataset.WriteXML("Results.xml")]  

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.