I'm looking to convert the below HTML Table markup into an XML format.
<table class='tbl-class'>
<thead>
<tr>
<th>Island</th>
<th>Number of nights</th>
</tr>
</thead>
<tbody>
<tr>
<td>Guadeloupe</td>
<td>1</td>
</tr>
<tr>
<td>Antigua</td>
<td>5</td>
</tr>
<tbody>
</table>
I would ideally like the XML output to be something like this:
<location>
<island>Guadeloupe</island>
<nights>1</nights>
</location>
<location>
<island>Antigua</island>
<nights>5</nights>
</location>
I'm currently attempting to use DOMDocument to do this but have little experience with it to get anywhere. So far i've done the following: - I think there's much more i need to be doing in the foreach loop but unsure what..
$doc = new DOMDocument();
$doc->load($convertedString);
$classname = 'tbl-class';
$finder = new DomXPath($doc);
$nodes = $finder->query("//*[contains(@class, '$classname')]");
foreach ($nodes as $node) {
$node->parentNode->removeChild($node);
}
$convertedString = $doc->saveHTML();