1

I want to convert an HTML file into an XML document using php. I've googled and been through some of stackoverflow's questions, but couldn't find any solution.

This is my html code and i want to convert it into XML doc.

<html>
<body>
    <ul>
    <li>Section 1</li>
    <li>Section 2
        <ul>
            <li>Section 2.1</li>
            <li>Section 2.2</li>
        </ul>
    </li>
    <li>Section 3</li>
</ul>
</body>
</html>

and i want it into

<root>
    <part>
        <number>Section 1</number>
        <number>Section 2</number>
            <child_number>Section 2.1</child_number>
            <child_number>Section 2.2</child_number>
        <number>Section 3</number>
    </part>
</root>

if there is any technique for converting this html file into XML using php, then please help me. Any help would be thankful.

darthVader
  • 197
  • 4
  • 17

1 Answers1

0

It looks like someone was able to do something similar to what you are looking for using tidy. Converting HTML to XML. If this is not an option then you may be left to writing a set of code that can handle your html files and export them to xml.

Community
  • 1
  • 1
Cameeob2003
  • 482
  • 1
  • 6
  • 16
  • I've been to solution you gave me, but once i tried that too, but somehow it was not working in this case, i have two files of HTML, if i m able to convert a small one then i m able to convert a large one, but i stuck in first step it self. is there any simpler way to do it, that code i found bit tricky. :( – darthVader Jul 24 '15 at 06:29
  • @unnat1993 unfortunately I can not seem to find one. I think that you may be stuck to manually converting it to XML unless someone else has a nifty tool they use to complete this task. – Cameeob2003 Jul 24 '15 at 06:35
  • i ll try, if i stuck here then i ll come here again.. And thank for positive reply. (Y) – darthVader Jul 24 '15 at 08:35