processing xml

  • hello all.

    I have this script:

    DECLARE @XML AS XML, @hDoc AS INT, @sql NVARCHAR (MAX)

    set @XML ='<Root>

    <WPID>4</WPID>

    <WPName>دي92</WPName>

    <Sum>0</Sum>

    <Result>03:30 , 18</Result>

    <Count>1</Count>

    </Root>'

    EXEC sp_xml_preparedocument @hDoc OUTPUT, @XML

    SELECT WPID, WPName, Sum, Result, Count

    FROM OPENXML(@hDoc, 'ROOT/Count/Result/Sum/WPName/WPID')

    WITH

    (

    WPID int '@WPID',

    WPName [varchar](100) '@WPName',

    Sum float '@Sum',

    Result [varchar](1000) '@Result',

    Count int '@Count'

    )

    EXEC sp_xml_removedocument @hDoc

    GO

    but it dosen,t get result,what is my wrong?thanks

  • Hi

    I tried the query like the below

    DECLARE @idoc int, @doc varchar(1000);

    SET @doc ='

    <ROOT>

    <AA wpid="4" WPName="??92" sum="0" result="03:30 , 18" count="1">

    </AA>

    </ROOT>';

    --Create an internal representation of the XML document.

    EXEC sp_xml_preparedocument @idoc OUTPUT, @doc;

    -- Execute a SELECT statement that uses the OPENXML rowset provider.

    SELECT *

    FROM OPENXML (@idoc, '/ROOT/AA',1)

    WITH (

    wpid int,

    wpname varchar(100),

    sum float,

    result varchar(1000),

    count int);

    It gave result. But could not find out what's wrong in your script

  • thanks for your reply.but I have fix xml file from another program,s out put and I can't change structure of xml.what should I do?

  • Try this

    DECLARE @XML AS XML, @hDoc AS INT

    SET @XML =

    '<Root>

    <WPID>4</WPID>

    <WPName>??92</WPName>

    <Sum>0</Sum>

    <Result>03:30 , 18</Result>

    <Count>1</Count>

    </Root>'

    EXEC sp_xml_preparedocument @hDoc OUTPUT, @XML

    SELECT WPID, WPName, Sum, Result, Count

    FROM OPENXML(@hDoc, 'Root')

    WITH

    (

    WPID int 'WPID',

    WPName [varchar](100) 'WPName',

    Sum float 'Sum',

    Result [varchar](1000) 'Result',

    Count int 'Count'

    )

    EXEC sp_xml_removedocument @hDoc

  • thanks alot.it works.:-)

Viewing 5 posts - 1 through 4 (of 4 total)

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