SQL Server Performance

XML parsing error b/c of attribute

Discussion in 'SQL Server 2005 General Developer Questions' started by stefanoale, Feb 3, 2010.

  1. stefanoale New Member

    I'm trying to parse xml that contains attributes which seems to be blowing up my code (sql 2k5 error:'XML parsing: ...undeclared prefix'), what am I doing wrong?
    If I remove the bold ' xsi:nil="true" ' the code is great, but the real xml file has attributes all over the place so I'm sure there is a way I'm just not familiar enough with XML to know.

    DECLARE @x xml;
    Set @x= '<?xml version="1.0"?> <main> <whyMe xsi:nil="true" /> <test> <row> <a>1</a> <b>2</b> </row> </test> </main> '

    DECLARE @iDoc int;
    EXEC sp_xml_preparedocument @iDoc OUTPUT, @x;

    SELECT * FROM OPENXML(@iDoc, '//row', 2) WITH (a int);

    EXEC sp_xml_removedocument @iDoc;
  2. satya Moderator

Share This Page