S'il vous plaît voir ci-dessous le script SQL Server 2005Type de données XML SQL Server requête numéro
Declare @xmlData XML
SET @xmlData = '<?xml version="1.0"?>
<bookstore xmlns="http://myBooks">
<book genre="autobiography" publicationdate="1981"
ISBN="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
<book genre="novel" publicationdate="1967"
ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<book genre="philosophy" publicationdate="1991"
ISBN="1-861001-57-6">
<title>The Gorgias</title>
<author>
<first-name>Sidas</first-name>
<last-name>Plato</last-name>
</author>
<price>9.99</price>
</book>
</bookstore>'
Select T.Item.query('.')
From @xmlData.nodes('/bookstore/book') AS T(Item)
Ce script devrait me donner la liste de tous les nœuds de livres. Mais ce n'est pas donner le comportement attendu. Si je supprime XMLNS alors ça fonctionne bien. Quelqu'un peut-il expliquer?
Ci-dessous fonctionne bien.
Declare @xmlData XML
SET @xmlData = '<?xml version="1.0"?>
<bookstore>
<book genre="autobiography" publicationdate="1981"
ISBN="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
<book genre="novel" publicationdate="1967"
ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<book genre="philosophy" publicationdate="1991"
ISBN="1-861001-57-6">
<title>The Gorgias</title>
<author>
<first-name>Sidas</first-name>
<last-name>Plato</last-name>
</author>
<price>9.99</price>
</book>
</bookstore>'
Select T.Item.query('.')
From @xmlData.nodes('/bookstore/book') AS T(Item)
Quelqu'un peut-il s'il vous plaît expliquer comment puis-je corriger premier scritp? Je veux lancer un script avec xmlns.