<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>XML &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/xml/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Tue, 21 Nov 2017 06:04:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>How to store and retrieve XML data into MySQL</title>
		<link>https://www.dbrnd.com/2015/08/store-retrieve-xml-data-type-node-into-mysql/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 13 Aug 2015 17:41:08 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[ExtractValue]]></category>
		<category><![CDATA[MySQL Command]]></category>
		<category><![CDATA[MySQL Database Administrator]]></category>
		<category><![CDATA[MySQL Database Designing]]></category>
		<category><![CDATA[MySQL Database Programming]]></category>
		<category><![CDATA[MySQL Error]]></category>
		<category><![CDATA[MySQL Performance Tunning]]></category>
		<category><![CDATA[MySQL Query]]></category>
		<category><![CDATA[MySQL Tips and Tricks]]></category>
		<category><![CDATA[XML]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=352</guid>

					<description><![CDATA[MySQL doesn&#8217;t support XML data types like Microsoft SQL Server or PostgreSQL. Many times it is required to store multiple nodes of data into a single column, in the form of XML. In the MySQL, You have to store XML in CLOB (Character Large Object) data type. MySQL provides different types of XML function so [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F08%2Fstore-retrieve-xml-data-type-node-into-mysql%2F&amp;linkname=How%20to%20store%20and%20retrieve%20XML%20data%20into%20MySQL" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F08%2Fstore-retrieve-xml-data-type-node-into-mysql%2F&amp;linkname=How%20to%20store%20and%20retrieve%20XML%20data%20into%20MySQL" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F08%2Fstore-retrieve-xml-data-type-node-into-mysql%2F&amp;linkname=How%20to%20store%20and%20retrieve%20XML%20data%20into%20MySQL" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F08%2Fstore-retrieve-xml-data-type-node-into-mysql%2F&amp;linkname=How%20to%20store%20and%20retrieve%20XML%20data%20into%20MySQL" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F08%2Fstore-retrieve-xml-data-type-node-into-mysql%2F&amp;linkname=How%20to%20store%20and%20retrieve%20XML%20data%20into%20MySQL" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F08%2Fstore-retrieve-xml-data-type-node-into-mysql%2F&amp;linkname=How%20to%20store%20and%20retrieve%20XML%20data%20into%20MySQL" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F08%2Fstore-retrieve-xml-data-type-node-into-mysql%2F&#038;title=How%20to%20store%20and%20retrieve%20XML%20data%20into%20MySQL" data-a2a-url="https://www.dbrnd.com/2015/08/store-retrieve-xml-data-type-node-into-mysql/" data-a2a-title="How to store and retrieve XML data into MySQL"></a></p><p>MySQL doesn&#8217;t support XML data types like Microsoft SQL Server or PostgreSQL.</p>
<p>Many times it is required to store multiple nodes of data into a single column, in the form of XML.</p>
<p>In the MySQL, You have to store XML in CLOB (Character Large Object) data type.</p>
<p>MySQL provides different types of XML function so using those functions, we can parse the XML data very easily.</p>
<p>Below is a full demonstration on storing and retrieval of XML data:</p>
<p><strong>First store XML data like any other string:</strong></p>
<pre class="crayon-plain-tag">CREATE DATABASE `Employee`;

CREATE TABLE Employee.XMLTest
(
	XMLDATA TEXT
);

INSERT INTO Employee.XMLTest 
VALUES
(
   '&lt;Students&gt;
      &lt;RollNumber&gt;1&lt;/RollNumber&gt;
      &lt;Name&gt;Anvesh&lt;/Name&gt;
      &lt;RollNumber&gt;2&lt;/RollNumber&gt;
      &lt;Name&gt;Neevan&lt;/Name&gt;
   &lt;/Students&gt;'
);</pre>
<p><strong>Second, Parsing this data using below stored procedure:</strong></p><pre class="crayon-plain-tag">DELIMITER $$
CREATE PROCEDURE Employee.usp_ParseXMLData()
BEGIN
    DECLARE i INT DEFAULT 1;
    DECLARE XMLText TEXT;
    DECLARE RNumber VARCHAR(50) ;   
    DECLARE RName VARCHAR(50);      
	    
    SET XMLText = (SELECT XMLDATA FROM Employee.XMLTest);        
  
    CREATE TEMPORARY TABLE Employee.TempXMLData 
    (    
        RollNumber VARCHAR(50)
        ,Name VARCHAR(50)
    ); 	
        
    SET RNumber = ExtractValue(XMLText, '//RollNumber[$i]');   
		             
    WHILE RNumber != "" DO                       
        SET RNumber = ExtractValue(XMLText, '//RollNumber[$i]');   
        SET RName = ExtractValue(XMLText, '//Name[$i]');          

	INSERT INTO Employee.TempXMLData 
	SELECT RNumber, RName; 	
        SET i = i+1;  	
    END WHILE;         
    SELECT 
	RollNumber
        ,Name
    FROM Employee.TempXMLData
    WHERE RollNumber &lt;&gt;'';   
	
    DROP TABLE Employee.TempXMLData;
END$$
DELIMITER ;</pre><p>
<p><strong>Call this stored procedure and check the result:</strong></p><pre class="crayon-plain-tag">CALL Employee.usp_ParseXMLData();</pre><p>
<a href="https://www.dbrnd.com/wp-content/uploads/2015/08/MySQLXML.png"><img decoding="async" class="alignnone wp-image-360 size-full" title="MySQL XML" src="https://www.dbrnd.com/wp-content/uploads/2015/08/MySQLXML.png" alt="MySQL XML" width="182" height="109" srcset="https://www.dbrnd.com/wp-content/uploads/2015/08/MySQLXML.png 182w, https://www.dbrnd.com/wp-content/uploads/2015/08/MySQLXML-180x109.png 180w, https://www.dbrnd.com/wp-content/uploads/2015/08/MySQLXML-150x90.png 150w" sizes="(max-width: 182px) 100vw, 182px" /></a></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL XML Type</title>
		<link>https://www.dbrnd.com/2015/05/postgresql-xml-type/</link>
					<comments>https://www.dbrnd.com/2015/05/postgresql-xml-type/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 22 May 2015 15:53:55 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[datatype]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[unnest]]></category>
		<category><![CDATA[XML]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=175</guid>

					<description><![CDATA[In this post, I am sharing a demonstration on the XML data type of PostgreSQL. Explain with the sample example. What is XML Type ? The XML Data type is used to store XML data. XML is well-formed storage structure of data. You can store multiple nodes into a single XML column. You can store [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fpostgresql-xml-type%2F&amp;linkname=PostgreSQL%20XML%20Type" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fpostgresql-xml-type%2F&amp;linkname=PostgreSQL%20XML%20Type" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fpostgresql-xml-type%2F&amp;linkname=PostgreSQL%20XML%20Type" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fpostgresql-xml-type%2F&amp;linkname=PostgreSQL%20XML%20Type" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fpostgresql-xml-type%2F&amp;linkname=PostgreSQL%20XML%20Type" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fpostgresql-xml-type%2F&amp;linkname=PostgreSQL%20XML%20Type" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fpostgresql-xml-type%2F&#038;title=PostgreSQL%20XML%20Type" data-a2a-url="https://www.dbrnd.com/2015/05/postgresql-xml-type/" data-a2a-title="PostgreSQL XML Type"></a></p><p>In this post, I am sharing a demonstration on the XML data type of PostgreSQL.</p>
<p>Explain with the sample example.</p>
<p><b>What is XML Type ?</b></p>
<p>The XML Data type is used to store XML data. XML is well-formed storage structure of data. You can store multiple nodes into a single XML column. You can store data in hierarchical format.</p>
<p><b>E.g, </b></p>
<p>User preferences table, in which User can select multiple preferences and even User can create custom choices for them.</p>
<p>Now, how you can store this preferences data for those Users.</p>
<p>Simple, create one XML column and store all User preferences id into this. like,</p>
<p>&lt;preferences&gt;&lt;id&gt;1&lt;/id&gt;&lt;id&gt;2&lt;/id&gt;&lt;id&gt;4&lt;/id&gt;&lt;/preferences&gt;.</p>
<p><b>Below is a demonstration of XML with PostgreSQL. </b></p>
<p><b>Basically you can store XML data with one child node or with different child node.</b></p>
<div>
<p><b><span style="font-size: x-large;">Les&#8217;s First start with one child node:<br />
</span></b> Create table with XML type:</p><pre class="crayon-plain-tag">CREATE TABLE XMLTEST (Name XML);</pre><p>
Now Insert XML Data.</p><pre class="crayon-plain-tag">INSERT INTO XMLTEST 
VALUES
('
    &lt;Root&gt;
          &lt;Sub&gt;abc&lt;/Sub&gt;
          &lt;Sub&gt;xyz&lt;/Sub&gt;
          &lt;Sub&gt;pqr&lt;/Sub&gt;
          &lt;Sub&gt;cdf&lt;/Sub&gt;
   &lt;/Root&gt;
');</pre><p>
Select data from XMLTEST:</p><pre class="crayon-plain-tag">SELECT *FROM XMLTEST</pre><p>
You can find above full XML into one column.</p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultOne.png"><img fetchpriority="high" decoding="async" class="aligncenter wp-image-178 size-full" title="XML Postgres Result One" src="https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultOne.png" alt="XMLPostgresResultOne" width="737" height="138" srcset="https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultOne.png 737w, https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultOne-300x56.png 300w, https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultOne-150x28.png 150w" sizes="(max-width: 737px) 100vw, 737px" /></a></p>
<p><b>Now, time to parse this XML column using unnest() function of PostgreSQL. </b></p><pre class="crayon-plain-tag">SELECT unnest(xpath('.//Sub/text()', Name::xml))::text AS XMLDATA FROM XMLTEST;</pre><p>
Result is:</p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultTwo.png"><img decoding="async" class="aligncenter wp-image-180 size-full" title="XML Postgres Result Two" src="https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultTwo.png" alt="XMLPostgresResultTwo" width="149" height="201" /></a></p>
<div>
<p>You can see this is four rows now, as we have stored different four values into one XML Column and after parse, we can see those four values in the form of different row.</p>
</div>
<div>
<p><b><span style="font-size: x-large;">Demonstration of different child node:</span></b></p><pre class="crayon-plain-tag">INSERT INTO XMLTEST VALUES
   ('
     &lt;BasicDetails&gt;
        &lt;Name&gt;Anvesh&lt;/Name&gt;
        &lt;City&gt;Hyderabad&lt;/City&gt;
        &lt;Gender&gt;Male&lt;/Gender&gt;
        &lt;Age&gt;27&lt;/Age&gt;
     &lt;/BasicDetails&gt; 
   ');

SELECT 
 unnest(xpath('//Name/text()', Name::XML)) AS Name
 ,unnest(xpath('//City/text()', Name::XML)) AS City
 ,unnest(xpath('//Gender/text()', Name::XML)) AS Gender
 ,unnest(xpath('//Age/text()', Name::XML)) AS Age
FROM XMLTEST;</pre><p>
</div>
<p><b>Result is :</b></p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultThree.png"><img loading="lazy" decoding="async" class="aligncenter wp-image-179 size-full" title="XML Postgres Result Three" src="https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultThree.png" alt="XMLPostgresResultThree" width="356" height="169" srcset="https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultThree.png 356w, https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultThree-300x142.png 300w" sizes="auto, (max-width: 356px) 100vw, 356px" /></a></p>
<p>In the above code, we inserted an XML data with different child nodes.</p>
<p>You can see the result of one row with the various columns for the different child nodes.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2015/05/postgresql-xml-type/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
	</channel>
</rss>
