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; TIA!!! Stefano
I think the angle-brackets (<, >) need to be escaped if they're part of the text and not part of the markup. That is part of the XML specification. The list of characters can be found here: http://en.wikipedia.org/wiki/List_o...r_entity_references#Character_entities_in_XML and http://msdn.microsoft.com/en-us/library/ms345117(SQL.90).aspx fyi. Also you hvaen't mentioned the errortext.