converting string to xml file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shivarnm
Forum Newbie
Posts: 2
Joined: Wed Jan 12, 2011 10:01 am

converting string to xml file

Post 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.
Last edited by shivarnm on Thu Jan 13, 2011 4:06 am, edited 1 time in total.
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: converting string to xml file

Post 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?
shivarnm
Forum Newbie
Posts: 2
Joined: Wed Jan 12, 2011 10:01 am

Re: converting string to xml file

Post 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.
kalpesh.mahida
Forum Commoner
Posts: 36
Joined: Wed Oct 06, 2010 7:09 am

Re: converting string to xml file

Post 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/
Post Reply