XML BASIC CONCEPTS - Exporting MySQL data to XML

In this tutorial, I will use a reference site.

Sometimes when you have a website with a lot of data on a MySQL database, is needed a backup, or a migration to another server using another DBMS.

I will use the ‘Products’ Example. There´s Products with Name and Prices.


<?php

/* Making the SQL query */
$query = “select * from products ORDER BY id_products”;
$results = mysql_query($query) or die ( mysql_error() );

echo “<products>”; /* Creating an element called ‘products’ */

/* Using while to return the query results */
while ($line = mysql_fetch_assoc($results) ) {

/* Creating a XML file with Elements Product, Name and Price */
echo “<product>”;
echo “<name>” . $line['name'] . “</name>”;
echo “<price>” . $line['price'] . “</price>”;
echo “</product>”;
}

/* Ending  startup element called ‘products’
echo “</products>”;

?>

On this example, we can make a very simple XML file through MySQL database. We can improve a lot this example, using attributes and another nested XML.   Another example, we can use a class - MySQL to XML - XML to MySQL developed by a brazilian, called Ricardo Costa. On linked website there´s examples how to use a PHP class to make this work.

Well… that´s the end! See you on the next post of ‘XML Series’

August 28 2008 | Tutorials | No Comments »

XML BASIC CONCEPTS:: DROPS

Howto: Using XQuery(with Nodes Method) to generate a XML file and after query the XML file on SQL Server 2005.
– USING ADVENTUREWORKS SAMPLE DATABASE

– DECLARE A VARIABLE WITH XML DATA-TYPE
DECLARE @xmlOrder xml
– SET THE VALUE OF DECLARED @xmlOrder VARIABLE USING A SELECT WITH STATEMENT ‘FOR XML AUTO’
SET @xmlOrder = (SELECT Cust.CustomerID CustID, CustomerType, SalesOrderID
FROM Sales.Customer Cust JOIN Sales.SalesOrderHeader [Order]
ON Cust.CustomerID = [Order].CustomerID
ORDER BY Cust.CustomerID
FOR XML AUTO)
– SELECT THE DATA OF XML GENERATED ON @xmlOrder VARIABLE
SELECT nCol.value(’@SalesOrderID’, ‘integer’) SalesOrderID
FROM @xmlOrder.nodes(’/Cust/Order’) AS nTable(nCol)

– THE RESULT WILL BE AN COLUMN CALLED SALESORDERID WITH VALUES OF SALESORDERID FROM THE  @xmlOrder VARIABLE.

August 28 2008 | Tutorials | No Comments »

XML BASIC CONCEPTS

XML, the Extensible Markup Language, is a W3C-endorsed standard for document markup. It defines a generic syntax used to mark up data with simple, human-readable tags. It provides a standard format for computer documents that is flexible enough to be customized for domains as diverse as web sites, electronic data interchange, vector graphics, genealogy, real estate listings, object serialization, remote procedure calls, voice mail systems, and more.

You can write your own programs that interact with, massage, and manipulate the data in XML documents. If you do, you’ll have access to a wide range of free libraries in a variety of languages that can read and write XML so that you can focus on the unique needs of your program. Or you can use off-the-shelf software, such as web browsers and text editors, to work with XML documents. Some tools are able to work with any XML document. Others are customized to support a particular XML application in a particular domain, such as vector graphics, and may not be of much use outside that domain. But the same underlying syntax is used in all cases, even if it’s deliberately hidden by the more user-friendly tools or restricted to a single application.

The first concept to understand XML files is understand Elements, Attributes and Character Data.

For example, if you have a table ‘person’ in a database with columns Id,Name, Age and Address, we can export this information using XML:

<person Id=”555″>
<Name> Gabriel </Name>
<Age> 28 </Age>
<Address> Street XYZ </Address>
</person>

In the first line, we have the element called ‘person’ with an attribute Id with a value ‘555′. In the second, third and fourth line we have elements which receives the contents ‘Gabriel’, ‘28′ and ‘Street XYZ’.
An element is delimited by the start-tag and the end-tag. Everything between the start-tag and the end-tag of the element (exclusive) is called the element’s content.

Example:
<Name> Gabriel </Name>

XML elements can have attributes. An attribute is a name-value pair attached to the element’s start-tag. Names are separated from values by an equals sign and optional whitespace. Values are enclosed in single or double quotation marks.

Example:
<person Id=”555″>

But… why use XML? For the basics, we can export database data, like table contents to our suppliers, partners and websites.
And more: there´s a lot of DBMS in the world. MySQL, Postgres, SQL, Oracle, DB2…
For now, you understood the basics of XML files, but we have a lot of things to learn, how make any DBMS export data to XML, how manipulate data on XML files…

But… stay calm… we will discuse this topics on anothers posts.

Well.. see you on another post!

*DBMS - Database management system

August 27 2008 | Tutorials | No Comments »

BI and Free Software: The answer

I received an answer from Kenia,  about Business Intelligence and Free Software. Honestly, I don´t know BizGres, a BI software to work with PostGreSQL. But I will make a test and a review about BiGres soon. Thanks by the answer, I still waiting answers for that question.

Links:
BizGres
Business Intelligence - Wikipedia

August 07 2008 | Review | No Comments »

Link:installing a local build service on openSUSE 11

http://jordimassaguerpla.blogspot.com/2008/08/installing-local-build-service-on.html

August 07 2008 | Hints | No Comments »

Bela Iniciativa

Gostaria de parabenizar por uma invenção tão significativa para a pomunidade brasileira. Como vamos *acabar com o desemprego* no país sem iniciativas brilhantes com essas?

Parabéns!

É  sério.  Aproveito para roubar ainda a frase do dia: Pequenos estados, grandes negócios!

August 07 2008 | News | No Comments »

Quote of the Day

Sorry, only PT_BR: “Adoro palestras onde os ditos “palestrantes” falam frases de efeito e mostram coisas impressionantes… é a melhor hora de fazer uma pergunta tosca e diferenciar um vendedor de um técnico.”

August 06 2008 | Review | No Comments »

BI and Free Software

I´m studying a lot BI(Business Inteligence) in the last weeks. But I have a question about MySQL and PostgreSQL and BI. There´s a tool to work with integration, analysis and reporting? Please, use the comments to talk about this, I want to know, I want to talk about this.

August 03 2008 | Review | 1 Comment »

Tchelinux em Pelotas

É com imenso orgulho que anunciamos o 2º Seminário de Software Livre Tchelinux Pelotas, que acontecerá no dia 23 de Agosto 2008 na UCPel em Pelotas. Nesta edição teremos 20 palestras com temas que vão desde conceitos sobre Software Livre orientadas para o público principiante até temas para usuários avançados. Como de costume o grupo não cobrará ingresso para entrada, contudo cada participante é encorajado a doar 2kg de alimentos não perecíveis que serão encaminhados à Instituições de Caridade de Pelotas.

Para aqueles que quiserem ajudar o grupo, no dia do evento estaremos vendendo camisetas do Tchelinux, mídias de distribuições Linux e adesivos.

Para maiores informações recomendamos a visita ao site do evento:

http://www.tchelinux.org/pelotas/

As inscrições para as 350 vagas já estão abertas, e podem ser feitas pelo formulário no site. Corra e garanta já o seu lugar!!

July 26 2008 | News | No Comments »

Link of the day: Not in My Backyard, Say an Increasing Number of Germans

http://www.spiegel.de/international/germany/0,1518,565146-2,00.html

July 16 2008 | News | No Comments »

Next »