none
c# - transform datatable to xml RRS feed

  • Question

  • I have a function that lives in a dll that is consumed by a legacy winform app.  Function returns a datatable.  DataTable has 4 columns:

    RowID, Included, Path, Val
    1, "true", "/*[local-name(.)=''][1]", "123abc"

    I need to expose the function in a web service and return the datatable in xml format like this:
    <return rowID="1" Included="true" path="../@*[local-name(.)='OrderId'][1]" Val="123abc" />

    Recommendation on best approach?

     

    • Moved by John Saunders Friday, January 13, 2012 2:19 AM ADO.NET Q (From:ASMX Web Services and XML Serialization)
    Thursday, January 12, 2012 7:55 PM

Answers

  • Is that the format of the XML that you have to use? I ask because that's not the normal xML that gets produced from a DataSet. The DataSet.GetXml() method produces XML that looks different than what you say you need.

    However, if you're stuck with the XML representation in your question, then I suggest you simply loop through your DataTable.Rows collection and use a string builder to format each row as you've indicated.

    If you need more information, let me know ...


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Monday, January 16, 2012 1:06 AM

All replies

  • Is that the format of the XML that you have to use? I ask because that's not the normal xML that gets produced from a DataSet. The DataSet.GetXml() method produces XML that looks different than what you say you need.

    However, if you're stuck with the XML representation in your question, then I suggest you simply loop through your DataTable.Rows collection and use a string builder to format each row as you've indicated.

    If you need more information, let me know ...


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Monday, January 16, 2012 1:06 AM
  • Hi,

    I am writing to check the status of the issue on your side.Would you mind letting us know the result of the suggestions?

    If you need further assistance, please feel free to let me know.I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, January 18, 2012 2:56 AM
    Moderator