It is recommended to get familiar with working with XML content  before proceeding with this tutorial.

In some cases it is necessary to store XML content in Data Source. In BellaDati it is possible to access and parse this data. This example shows how to parse data imported from MySQL database.

Preparation

The database table test contains sample data about books. For the purpose of trying this scenario, you can insert data into table with this command:

INSERT INTO test(id, name, title, copies)
VALUES (5593372,'Kim Casali','Love is: cartoons from the Daily Mail',
'<?xml version="1.0" encoding="UTF-8"?>
<copies>
<copy id="GB7213422">
<version>Ver1</version><year>1997</year><pages>82</pages></copy>
<copy id="GB7634751"><version>Ver2</version><year>1976</year><pages>80</pages></copy>
</copies>'),
(5626884,'Bill Tidy','Fosdyke saga','<?xml version="1.0" encoding="UTF-8"?>
<copies>
<copy id="GB7731336">
<version>Ver1</version><year>1977</year><pages>160</pages></copy>
<copy id="GB7927739">
<version>Ver2</version><year>1978</year><pages>160</pages></copy>
<copy id="GB8004327">
<version>Ver3</version><year>1979</year><pages>160</pages></copy>
</copies>');


As you can see, last column contains list of copies which is stored in XML and has following structure:

<?xml version="1.0" encoding="UTF-8"?>
<copies>
	<copy id="">
		<version>Version number</version>
		<year>Year of publication</year>
		<pages>Number of pages</pages>
	</copy>
</copies>

Working with XML Content

Set up an import of this table into BellaDati. On import settings page, add new columns that will contain parsed data. In BellaDati xPath is used for selecting XML elements.

Getting ID of first version
xpathElementAttribute(value(1),"/copies/copy","id")

This code returns id of first copy for each book.

Getting latest year of publication
xpathElementContent(value(1), "/copies/copy[last()]/year")

This code looks for last version and then returns its year of publication.

  • No labels