Creation of XML

  • Hello I want to create a XML file with data in my table. I have a question about tags.

    SELECT

    -- Root element attributes

    'http://tempuri.org/Form.xsd' AS 'xmlns',

    'http://www.w3.org/2001/XMLSchema-instance' AS 'xmlns:xsd',

    (

    SELECT

    -- Creating a default element

    (

    SELECT Id

    FROM Rav.kr_TM100ASTeminatlarDosyasi

    FOR XML PATH('Satir'),

    ELEMENTS,

    TYPE

    )

    FOR XML PATH('Veri'),

    TYPE

    )

    FOR XML RAW('Form')

    )

    This is my query. When I use 'xmlns' namespace the result is below:

    <Form xmlns="http://tempuri.org/Form.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance">

    <Veri xmlns="">

    <Satir>

    <Id>1</Id>

    </Satir>

    </Veri>

    </Form>

    I dont want to see 'xmlns' in 'Veri' tag. When I use xmlna or another word instead of 'xmlns' the result is below:

    <Form xmlns="http://tempuri.org/Form.xsd" xmlna:xsd="http://www.w3.org/2001/XMLSchema-instance">

    <Veri>

    <Satir>

    <Id>1</Id>

    </Satir>

    </Veri>

    </Form>

    How can I remove 'xmlns' from 'Veri' tag while using it in 'Form' tag

    Thanks

  • As I'm not familiar with how the XML stuff works in sufficient detail, all I can offer is a simple REPLACE:

    SELECT REPLACE(

    (

    SELECT

    -- Root element attributes

    'http://tempuri.org/Form.xsd' AS xmlns,

    'http://www.w3.org/2001/XMLSchema-instance' AS 'xmlns:xsd',

    (

    SELECT

    -- Creating a default element

    (

    SELECT Id = 1

    FOR XML PATH('Satir'),

    ELEMENTS,

    TYPE

    )

    FOR XML PATH('Veri'),

    TYPE

    )

    FOR XML RAW('Form')

    ), ' xmlns=""', '') AS XML_RAW

    I'm sure it won't be satisfying, but it might not be problematic, either.

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • It is useful, thank you. I wonder why 'xlmns' effects sub tag of root.

Viewing 3 posts - 1 through 2 (of 2 total)

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