Home Forums Programming XML problems with OPENXML - how to avoid using the xmlns RE: problems with OPENXML - how to avoid using the xmlns

  • See if something along these lines works for you:

    DECLARE @doc NVARCHAR(MAX)

    SET @doc = N'

    <UNODocument

    docID="DispHNRP"

    xmlns="http://www.theUNO.com/schema"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://www.theUNO.com/schema http://reports.theCASO.com/docrefs/schema/DispHNRP_r1.xsd">

    <UNODocHeader>

    <DocTitle>Commodity Price (HNRP) Report</DocTitle>

    <DocRevision>1</DocRevision>

    <DocConfidentiality>

    <DocConfClass>PUB</DocConfClass>

    </DocConfidentiality>

    <CreatedAt>2011-04-04T09:01:27</CreatedAt>

    </UNODocHeader>

    <UNODocBody>

    <Date>2011-04-04</Date>

    <HNRPs>

    <HNRP>

    <Hour>1</Hour>

    <Price>134.3</Price>

    <DataSource>TSO_RP</DataSource>

    </HNRP>

    <HNRP>

    <Hour>2</Hour>

    <Price>229.09</Price>

    <DataSource>TSO_RP</DataSource>

    </HNRP>

    <HNRP/>

    </HNRPs>

    </UNODocBody>

    </UNODocument>'

    DECLARE @docHandle INT

    EXEC sp_xml_preparedocument

    @docHandle OUTPUT,

    @doc,

    N'<root xmlns:n="http://www.theUNO.com/schema" />'

    --SELECT * FROM OPENXML (@docHandle,'/',3);

    SELECT *

    FROM OPENXML(@docHandle, '/n:UNODocument/n:UNODocBody/n:HNRPs/n:HNRP', 2)

    WITH

    (

    [Date] NVARCHAR(20) '../../n:Date',

    [Hour] NVARCHAR(20) './n:Hour',

    Price NVARCHAR(20) './n:Price')

    EXEC sp_xml_removedocument

    @docHandle

    GO

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato