Page 1 of 1

converting string to xml file

Posted: Wed Jan 12, 2011 10:07 am
by shivarnm
i've a string and it has to be converted to xml file by looking at some certain rule .

string in DB column is like ,

I) Title I
II) Titre II
A. Sous-Titre A
B. Sous-titre B
III) Titre III
A. sssSous-Titre A
B. xxxxSous-Titre Bf


so above string should be stored as a xml file in the format ,

<?xml version="1.0" encoding="iso-8859-1" ?>
<DOCUMENT>
<part1 identifier="1">
<name>Title I</name>
</part1>
<part2 identifier="2">
<name>Titre II</name>
<part21 identifier="21">
<name>Sous-Titre A</name>
</part21>
<part22 identifier="22">
<name>Sous-titre B</name>
</part22>
</part2>
<part3 identifier="3">
<name>Titre III</name>
<part31 identifier="31">
<name>sssSous-Titre A</name>
</part31>
<part32 identifier="32">
<name>xxxxSous-Titre Bf</name>
</part32>
</part3>
</DOCUMENT>

what way it will be better do the above task.

thanks in advance.

Re: converting string to xml file

Posted: Wed Jan 12, 2011 1:37 pm
by greyhoundcode

Code: Select all

<part21 identifier="21">
<name>Sous-Titre A</name>
</part21>
<part22 identifier="22">
<name>Sous-titre B</name>
</part22>
What caught my eye is that, for instance, you have an element named part21 with an identifier attribute also set to 21, and this pattern repeats. Is this a piece of ad hoc XML or do you have an actual schema document you are working to?

Re: converting string to xml file

Posted: Wed Jan 12, 2011 11:35 pm
by shivarnm
thanks greyhoundcode for ur reply,

am not using any schema, not sure ad hoc . at the end i've to save the string in xml file, its the requirement.

Re: converting string to xml file

Posted: Thu Jan 13, 2011 12:39 am
by kalpesh.mahida
Using DOM library you can easily create XML files from SQL data.

Take a look at few articles, hope those will help you.

http://www.tonymarston.net/php-mysql/dom.html
http://www.ibm.com/developerworks/library/os-xmldomphp/