FOR XML PATH + file structure

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vins

    FOR XML PATH + file structure

    Hey there,

    I used the FOR XML PATH feature but the XML result is in only one line,
    it does not conserve the XML structure (treeview). When I open the XML
    file with IE, it s working very (I have the XML hierarchy) but when I
    use Visual Studio or other tool to edit it, I ve just one line!

    For example:
    <children group=""><child firstname="" lastname=""></child>=""><chil d
    firstname=""
    lastname=""></child>......... ............... ......</children>...... ......

    And I d like to have
    <children group="">
    <child firstname="" lastname=""></child>="">
    <child firstname="" lastname=""></child>
    ............... ...............
    </children>
    ..............

    To give you an example of the query:

    SELECT Child.group AS '@group',

    (SELECT firstname AS '@firstname',
    lastname AS '@lastname'

    FROM Collecte_Data_E xtract cde

    FOR XML PATH('child'), TYPE)

    FROM Feed AS Child
    FOR XML PATH('children' ), TYPE

    Any idea?
    Many thanks in advance

  • Erland Sommarskog

    #2
    Re: FOR XML PATH + file structure

    Vins (vbellet@gmail. com) writes:
    I used the FOR XML PATH feature but the XML result is in only one line,
    it does not conserve the XML structure (treeview). When I open the XML
    file with IE, it s working very (I have the XML hierarchy) but when I
    use Visual Studio or other tool to edit it, I ve just one line!
    Trying running the query in Mgmt Studio, and then double-click on the
    XML document to open it the XML viewer. If you save from the viewer
    you get the format you are looking for.



    --
    Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.se

    Books Online for SQL Server 2005 at

    Books Online for SQL Server 2000 at

    Comment

    • Vins

      #3
      Re: FOR XML PATH + file structure

      Thanks Erland but I want to do this dynamically, it s boring to do this
      for each file (it s a daily report)

      Other idea?

      Comment

      • Erland Sommarskog

        #4
        Re: FOR XML PATH + file structure

        Vins (vbellet@gmail. com) writes:
        Thanks Erland but I want to do this dynamically, it s boring to do this
        for each file (it s a daily report)
        If it's a daily report, I assume that you run the program from a client.
        Then I guess there is a suitable API that you can use to format your XML.


        --
        Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.se

        Books Online for SQL Server 2005 at

        Books Online for SQL Server 2000 at

        Comment

        Working...