T-SCRIPT XML

  • Hi All,

    I have this sample xml data with subgroups. I have identified the fields in the source data. I wanted to check if anyone can give me some idea, how can I get the xml output like these from those data. Or someone can point me to the url where I can generate such XML with sub-headers and trailers.

    Thanks,

    SB009

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • Can you post the XML and your desired results?

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • This was removed by the editor as SPAM

  • OK, that's an example of the source data. Based on that, what do you want to see? I do not see any 'subgroups' in this example.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Is this what you're looking for?

    DECLARE @MailMessage TABLE (
    "to" VARCHAR(100),
    "from" VARCHAR(100),
    "heading" VARCHAR(100),
    "body" VARCHAR(1000)
    )
    INSERT INTO @MailMessage ("to", "from", "heading", "body")
    VALUES
    ('Tove','Jani','Reminder','Don''t forget me this weekend!')
    , ('Jani','Tove','RE: Reminder','Certainly not! Count on me. :-)')

    SELECT CONCAT('<?xml version="1.0" encoding="UTF-8"?>','<root>',(SELECT * FROM @MailMessage
    FOR XML PATH('note')),'</root>') as XMLout

    This will output an XML string that looks like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <root>
    <note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
    </note>
    <note>
    <to>Jani</to>
    <from>Tove</from>
    <heading>RE: Reminder</heading>
    <body>Certainly not! Count on me. :-)</body>
    </note>
    </root>

    • This reply was modified 2 years, 1 month ago by  kaj.
    • This reply was modified 2 years, 1 month ago by  kaj. Reason: Added root element and XML output
    • This reply was modified 2 years, 1 month ago by  kaj. Reason: Changed output format type from XML to Plain, because the "pretty print" was otherwise lost

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply