Parse MathML in XML and PHP

777 Views Asked by At

I need to parse the MathML in XML using php

Here the sample code for MathML in my XML (ref):

<mathDisplay numbered="yes" id="van005-mdis-0001">
  <mrow>
    <mrow selected="true">
      <msup><mo>sin</mo><mn>2</mn></msup>
      <mi>&theta;</mi>
      <mo>+</mo>
      <msup><mo>cos</mo><mn>2</mn></msup>
      <mi>&theta;</mi>
      <mo>=</mo><mn>1</mn>
    </mrow>
  </mrow1>
</mathDisplay>

Please help me to parse the mathml from XML in php

1

There are 1 best solutions below

4
On

You can use SimpleXML to parse a XML file.

Edit:

<?php
$xml = simplexml_load_string($xmlstring);
var_dump($xml)
echo $xml->yournode;
?>