- Prison Code Breaker Diary -

=> aka: Nhật Kí Code Tù

Categories

Showing posts with label XML. Show all posts

Language: Perl
Presiquisite: XML::Simple

Assuming we have a xml file like this: data.xml

<?xml version="1.0" encoding="UTF-8"?>
<database>
<user>
<uname>Pete Houston</uname>
<upass>123456</upass>
<email>pete.houston.17187@gmail.com</email>
<id>1</id>
</user>
<user>
<uname>Bach Van Kim</uname>
<upass>987654</upass>
<email>bvkvn06@gmail.com</email>
<id>2</id>
</user>
</database>
We will dump this XML tree using XML::Simple and Dumper package:

#!C:\perl\bin\perl.exe -w
use strict;
use XML::Simple;
use Data::Dumper;

print Dumper( XML::Simple->new()->XMLin("data.xml"));

The result shows:

$VAR1 = {
'user' => {
'1' => {
'email' => 'pete.houston.17187@gmail.com',
'uname' => 'Pete Houston',
'upass' => '123456'
},
'2' => {
'email' => 'bvkvn06@gmail.com',
'uname' => 'Bach Van Kim',
'upass' => '987654'
}
}
};

The method: XML::Simple->new() will create an object to handle XML file, and then input file will be called through method XMLin("filename.xml");
A very simple way!

First, make sure you installed libxml2.
Get it from here: LibXml2

Open Eclipse, New Project -> C Project.

On the menu Project, choose Properties, left pane: C/C++ Build - right pane: tab Tool Settings, choose GCC C Linker -> Libraries. On Libraries box, add "xml2". Then Apply -> OK

Left pane: C/C++ General -> Paths & Symbols, under tab Includes, under Languages list choose GNU C, click Add, type "/usr/include/libxml2". Then Apply -> OK.

Have fun!@