﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by Jacob Sebastian / Article Discussions / Article Discussions by Author  / XML Workshop X - Working with namespaces / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 18 May 2013 19:54:10 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: XML Workshop X - Working with namespaces</title><link>http://www.sqlservercentral.com/Forums/Topic412439-356-1.aspx</link><description>Need to do some "homework" with the namespaces feature.Here is the code with comments in spanish:[code="sql"]--=================================================================================================================================-- XML Workshop Part V Namespaces: el uso de NAMESPACES permite desambiguar el nombre de los elementos/*	normalmente en SQL usamos alias para desambiguar, en programación usamos clase.procedimiento para diferenciar 2 llamadas	iguales en diferentes clases. En XML usamos Namespaces*/--=================================================================================================================================--vamos a crear un XML de ejemplo/*&amp;lt;configuration&amp;gt;   &amp;lt;connection&amp;gt;	 &amp;lt;provider&amp;gt;World Wide Internet Providers&amp;lt;/provider&amp;gt;	 &amp;lt;speed&amp;gt;512 KBPS&amp;lt;/speed&amp;gt;   &amp;lt;/connection&amp;gt;   &amp;lt;connection&amp;gt;	 &amp;lt;provider&amp;gt;SQL Client Provider&amp;lt;/provider&amp;gt;	 &amp;lt;protocol&amp;gt;TCP/IP&amp;lt;/protocol&amp;gt;	 &amp;lt;Authentication&amp;gt;Windows&amp;lt;/Authentication&amp;gt;  &amp;lt;/connection&amp;gt;&amp;lt;/configuration&amp;gt; una aplicación que intente leer el XML anterior fallará pues tenemos el nodo connection repetido, aunque uno se refiere a Internet y el otro a SQL  modifiquemos el XML para tener en cuenta los namespaces&amp;lt;configuration	 xmlns:net="urn:www.dotnetquest.com/internetconnection"	 xmlns:db="urn:www.dotnetquest.com/databaseconnection"&amp;gt;   &amp;lt;net:connection&amp;gt;	 &amp;lt;net:provider&amp;gt;World Wide Internet Providers&amp;lt;/net:provider&amp;gt;	 &amp;lt;net:speed&amp;gt;512 KBPS&amp;lt;/net:speed&amp;gt;   &amp;lt;/net:connection&amp;gt;   &amp;lt;db:connection&amp;gt;	 &amp;lt;db:provider&amp;gt;SQL Client Provider&amp;lt;/db:provider&amp;gt;	&amp;lt;db:protocol&amp;gt;TCP/IP&amp;lt;/db:protocol&amp;gt;	&amp;lt;db:Authentication&amp;gt;Windows&amp;lt;/db:Authentication&amp;gt;  &amp;lt;/db:connection&amp;gt;&amp;lt;/configuration&amp;gt;*/--Veamos como generar un XML con esta estructura, primero crearemos las tablas necesarias e introduzcamos datos-- Create the table for Net Connection-- be aware that if using AdventureWorks database it has already a NetConnection table, you can temporary rename it or change test table nameCREATE TABLE NetConnection (Provider VARCHAR(50),Speed VARCHAR(20))-- Populate the TableINSERT INTO NetConnection(Provider, Speed)SELECT 'World Wide Internet Providers','512 KBPS'-- Create table for DB ConnectionCREATE TABLE DbConnection (Provider VARCHAR(50),Protocol VARCHAR(20),[Authentication] VARCHAR(20))-- Populate the TableINSERT INTO DbConnection (Provider,Protocol,[Authentication] )SELECT	'SQL Client Provider','TCP/IP','Windows'--ahora crearemos el XML, usando la sentencia TSQL: WITH XMLNAMESPACESWITH XMLNAMESPACES (    'urn:www.dotnetquest.com/internetconnection' AS net,    'urn:www.dotnetquest.com/databaseconnection' AS db)SELECT net.Provider AS 'net:Connection/net:Provider',	net.Speed AS 'net:Connection/net:Speed',	db.Provider AS 'db:Connection/db:Provider',	db.Protocol AS 'db:Connection/db:Protocol',	db.[Authentication] AS 'db:Connection/db:Authentication'	 FROM NetConnection netCROSS JOIN DbConnection dbFOR XML PATH('Configuration')[/code]</description><pubDate>Fri, 23 Dec 2011 08:13:14 GMT</pubDate><dc:creator>yazalpizar_</dc:creator></item><item><title>RE: XML Workshop X - Working with namespaces</title><link>http://www.sqlservercentral.com/Forums/Topic412439-356-1.aspx</link><description>you are right.Here is an example that generates CDATA and namespace declarations.[code]SELECT	1 AS Tag,	NULL AS Parent,	'Jacob' AS 'Person!1!Name!element',	'Hellow world' AS 'Person!1!greeting!CDATA',	'http://beyondrelational.com/xml.aspx' 		AS 'Person!1!xmlns:x'FOR XML EXPLICIT[/code]</description><pubDate>Sat, 06 Feb 2010 09:11:52 GMT</pubDate><dc:creator>jacob sebastian</dc:creator></item><item><title>RE: XML Workshop X - Working with namespaces</title><link>http://www.sqlservercentral.com/Forums/Topic412439-356-1.aspx</link><description>"The following FOR XML features are not supported with WITH XMLNAMESPACES list: EXPLICIT mode, XMLSCHEMA and XMLDATA directives."Okay, this is the message I was getting in the first place, which prompted me to ask my original question.  I can only guess what you're trying to tell me is not to use XMLNAMESPACES and in the same statement where I'm using EXPLICIT mode to generate the body of the results.</description><pubDate>Fri, 29 Jan 2010 07:13:17 GMT</pubDate><dc:creator>JWIDM76</dc:creator></item><item><title>RE: XML Workshop X - Working with namespaces</title><link>http://www.sqlservercentral.com/Forums/Topic412439-356-1.aspx</link><description>You can use WITH XMLNAMESPACES() to generate namespace information along with the generated XML. You can use FOR XML EXPLICIT to generate CDATA sections.</description><pubDate>Thu, 28 Jan 2010 22:10:08 GMT</pubDate><dc:creator>jacob sebastian</dc:creator></item><item><title>RE: XML Workshop X - Working with namespaces</title><link>http://www.sqlservercentral.com/Forums/Topic412439-356-1.aspx</link><description>I'm using 2005.  I need to specify namespace AND use CDATA.  I was wondering if there was a method for achieving both.Thank you.</description><pubDate>Thu, 28 Jan 2010 20:10:55 GMT</pubDate><dc:creator>JWIDM76</dc:creator></item><item><title>RE: XML Workshop X - Working with namespaces</title><link>http://www.sqlservercentral.com/Forums/Topic412439-356-1.aspx</link><description>Which version of SQL Server are you using? If you are on SQL Server 2005 or above, you can use WITH XMLNAMESPACES() to generate an XML document with namespace information.if you need CDATA sections, you need to use EXPLICIT.</description><pubDate>Thu, 28 Jan 2010 19:27:23 GMT</pubDate><dc:creator>jacob sebastian</dc:creator></item><item><title>RE: XML Workshop X - Working with namespaces</title><link>http://www.sqlservercentral.com/Forums/Topic412439-356-1.aspx</link><description>I believe I need to use FOR XML EXPLICIT because of my need for the CDATA directive, and I also want to be able to have a collection based on a related table (the SKU's in the example below) within my XML results.  Is there a way to specify a namespace when using FOR XML EXPLICIT or on the flip side is there a way for me to have CDATA and collections if I don't use EXPLICIT mode.I need my results to look like this:[code="xml"]&amp;lt;product:product xmlns:product="http://www.myco.com/product" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.myco.com/product rl-product+CustomProductCatalog+product.xsd " xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/" ID="productprod000191" repositoryId="prod000191"&amp;gt;	&amp;lt;product:product.heightMax xsi:nil="true"/&amp;gt;	&amp;lt;product:product.gender collectionType="List" componentType="string"&amp;gt;		&amp;lt;product:string&amp;gt;Womens&amp;lt;/product:string&amp;gt;	&amp;lt;/product:product.gender&amp;gt;	&amp;lt;product:product.displayName xsi:type="string"&amp;gt;&amp;lt;![CDATA[a shirt, logo]]&amp;gt;&amp;lt;/product:product.displayName&amp;gt;	&amp;lt;product:product.id xsi:type="string"&amp;gt;&amp;lt;![CDATA[prod000191]]&amp;gt;&amp;lt;/product:product.id&amp;gt;	&amp;lt;product:product.color collectionType="List" componentType="string"&amp;gt;		&amp;lt;product:string&amp;gt;Red&amp;lt;/product:string&amp;gt;		&amp;lt;product:string&amp;gt; White&amp;lt;/product:string&amp;gt;	&amp;lt;/product:product.color&amp;gt;	&amp;lt;product:product.childSKUs collectionType="List" componentType="itemRef"&amp;gt;		&amp;lt;product:childSKUssku ID="sku84016" repositoryId="84016"&amp;gt;			&amp;lt;product:sku.displayName xsi:type="string"&amp;gt;&amp;lt;![CDATA[small, green]]&amp;gt;&amp;lt;/product:sku.displayName&amp;gt;			&amp;lt;product:sku.newSku xsi:type="boolean"&amp;gt;true&amp;lt;/product:sku.newSku&amp;gt;			&amp;lt;product:sku.listPrice xsi:type="double"&amp;gt;16.95&amp;lt;/product:sku.listPrice&amp;gt;			&amp;lt;product:sku.id xsi:type="string"&amp;gt;&amp;lt;![CDATA[84016]]&amp;gt;&amp;lt;/product:sku.id&amp;gt;		&amp;lt;/product:childSKUssku&amp;gt;		&amp;lt;product:childSKUssku ID="sku84020" repositoryId="84020"&amp;gt;			&amp;lt;product:sku.displayName xsi:type="string"&amp;gt;&amp;lt;![CDATA[large, green]]&amp;gt;&amp;lt;/product:sku.displayName&amp;gt;			&amp;lt;product:sku.newSku xsi:type="boolean"&amp;gt;true&amp;lt;/product:sku.newSku&amp;gt;			&amp;lt;product:sku.listPrice xsi:type="double"&amp;gt;16.95&amp;lt;/product:sku.listPrice&amp;gt;			&amp;lt;product:sku.id xsi:type="string"&amp;gt;&amp;lt;![CDATA[84020]]&amp;gt;&amp;lt;/product:sku.id&amp;gt;		&amp;lt;/product:childSKUssku&amp;gt;	&amp;lt;/product:product.childSKUs&amp;gt;	&amp;lt;product:product.form xsi:nil="true"/&amp;gt;&amp;lt;/product:product&amp;gt;[/code]What mode do you recommend?</description><pubDate>Thu, 28 Jan 2010 12:05:20 GMT</pubDate><dc:creator>JWIDM76</dc:creator></item><item><title>RE: XML Workshop X - Working with namespaces</title><link>http://www.sqlservercentral.com/Forums/Topic412439-356-1.aspx</link><description>[quote][b]Ryan Riley (11/7/2007)[/b][hr]Great article, Jacob. I think you might have mentioned this previously, but is there a limit to the number of characters an XML query will return? Also, is there a way to get around this limitation? My queries keep coming back as only the first several thousand characters.Thanks![/quote]Ryan,I do not think there is a limitation. The following query returns an XML stream that is half a million characters long.DECLARE @x XMLSELECT @x = (	select * from sys.columns for xml auto)SELECT LEN(CAST (@x as VARCHAR(MAX)))/*OUTPUT:--------------------417597(1 row(s) affected)*/</description><pubDate>Wed, 07 Nov 2007 23:37:35 GMT</pubDate><dc:creator>jacob sebastian</dc:creator></item><item><title>RE: XML Workshop X - Working with namespaces</title><link>http://www.sqlservercentral.com/Forums/Topic412439-356-1.aspx</link><description>Great article, Jacob. I think you might have mentioned this previously, but is there a limit to the number of characters an XML query will return? Also, is there a way to get around this limitation? My queries keep coming back as only the first several thousand characters.Thanks!</description><pubDate>Wed, 07 Nov 2007 10:07:24 GMT</pubDate><dc:creator>panesofglass</dc:creator></item><item><title>XML Workshop X - Working with namespaces</title><link>http://www.sqlservercentral.com/Forums/Topic412439-356-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/articles/XML/61333/"&gt;XML Workshop X - Working with namespaces&lt;/A&gt;[/B]</description><pubDate>Thu, 18 Oct 2007 15:07:48 GMT</pubDate><dc:creator>jacob sebastian</dc:creator></item></channel></rss>