0

I have a problem that I'm trying to solve with XSLT as it seems like a really elegant and scalable solution. The ordering applicaiton that I'm trying to write can have any number of items in it. I'm reasonably new at PHP/HTML and trying to migrate my skills across to some raw HTML as the workplace I'm in doesn't like libraries (don't ask...)

Problem - pass the contents of an HTML table as a parameter to a PHP page for processing and lodging/paying for an order. The XML is then lodged in the database and processed server side with an insert trigger. The class tag is the field indicator as is also indicated some on screen CSS formatting.

Additional help would be to properly escape the characters so that I don't get an injection attack...

I hope this makes sense... so please be kind - it's my first question here after searching all sorts of related & similar answers that don't really seem to help...

Many ... many thanks in advance of your kind assistance.

The HTML Table:

<?xml version="1.0" encoding="UTF-8"?>
<table id="MyOrder">
  <tr>
    <td class="title">Empire Burlesque</td>
    <td class="artist">Bob Dylan</td>
    <td class="country">USA</td>
    <td class="company">Columbia</td>
    <td class="price">10.90</td>
    <td class="year">1985</td>
  </tr>
  <tr>
    <td class="title">Hide your heart</td>
    <td class="artist">Bonnie Tyler</td>
    <td class="country">UK</td>
    <td class="company">CBS Records</td>
    <td class="price">9.90</td>
    <td class="year">1988</td>
  </tr>
  <tr>
    <td class="title">Greatest Hits</td>
    <td class="artist">Dolly Parton</td>
    <td class="country">USA</td>
    <td class="company">RCA</td>
    <td class="price">9.90</td>
    <td class="year">1982</td>
  </tr>

The Desired XML

<?xml version="1.0" encoding="UTF-8"?>
<order>
  <item>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</company>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </item>
  <item>
    <title>Hide your heart</title>
    <artist>Bonnie Tyler</artist>
    <country>UK</country>
    <company>CBS Records</company>
    <price>9.90</price>
    <year>1988</year>
  </item>
  <item>
    <title>Greatest Hits</title>
    <artist>Dolly Parton</artist>
    <country>USA</country>
    <company>RCA</company>
    <price>9.90</price>
    <year>1982</year>
  </item>
</order>
Community
  • 1
  • 1
btg
  • 1
  • In case your HTML is not as strict as it looks, use DOMDocument and `loadHTML()` to read the contents, then you should be able to create the target in either DOMDocument (for consistency) or SimpleXML. Both of these API's are part of PHP, so don't require external libraries. – Nigel Ren Mar 10 '20 at 09:56
  • Hi Nigel, the HTML is as strict as it looks :-) I had a really look at the article refenced in closing this question and can't seem to find the answer- any pointers on where to look further? – btg Mar 10 '20 at 10:16
  • Start by looking at https://stackoverflow.com/questions/4979836/domdocument-in-php/4983721#4983721 to see how to read the HTML. If you make some progress, you can always post a new question with where you have got and where you are having problems. – Nigel Ren Mar 10 '20 at 15:13

0 Answers0