Reading XML from ntext field

  • Hi there.

    I'm just wondering whether anyone has/knows-of a method to read xml from an ntext field into normalised tables or even just read the xml and display the results with appropriate column headings.

    I'm guessing the schema would have to be defined as well somehow to aid in this process - is there an easy way to discover/display the schema?

    Thanks,

    Dave

  • Look up sp_xml_preparedocument (and sp_xml_removedocument) in Books Online.

    In SQL 2000 you're limited to XML instances (i.e. their character representations) not exceeding 8000 Bytes varchar (4000 Bytes nvarchar) as [n]text variables are not supported.

    If your XML instances are larger than that then your best option is to parse the XML using a client application.

    ML

    ---
    Matija Lah, SQL Server MVP
    http://milambda.blogspot.com

  • [font="Verdana"]

    Create Procedure {Proc Name}

    (@xml nText)

    As

    ...

    Declare @XmlHandle Int

    Declare @r Int

    Set @XmlHandle = Null

    -- prepare document from xml

    Exec @r = sp_xml_preparedocument @XmlHandle OutPut, @xml

    ....

    -- remove document from xml

    Exec sp_xml_removedocument @XmlHandle

    ...

    Mahesh

    [/font]

    MH-09-AM-8694

  • And how can one use this procedure in T-SQL if the [n]text variables aren't supported?

    ML

    ---
    Matija Lah, SQL Server MVP
    http://milambda.blogspot.com

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

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