Search code examples
phpxmloracle-databasexmltype

PHP string not formatted as valid XML


I have created a string that I want to pass to an Oracle database as a CLOB and then I run XMLTYPE.createxml on the CLOB, but when I do this it keeps giving the error LPX-00007: unexpected end-of-file encountered.

I've checked everything and can't seem to see whats going on, is the string invalid XML or am I missing something!?

XML

<?xml version="1.0" encoding="UTF-8" ?>
<location>
    <id>23451</id>
    <code>2</code>
    <date>20151217</date>
</location>
<location>
    <id>23452</id>
    <code>3</code>
    <date>20151217</date>
</location>
<location>
    <id>23453</id>
    <code>3</code>
    <date>20151217</date>
</location>

Solution

  • To make your XML well-formed you need single root element:

    <?xml version="1.0" encoding="UTF-8" ?>
    <root>
      <location>
        <id>23451</id>
        <code>2</code>
        <date>20151217</date>
      </location>
      <location>
        <id>23452</id>
        <code>3</code>
        <date>20151217</date>
      <location>
      <location>
        <id>23453</id>
        <code>3</code>
        <date>20151217</date>
      </location>
    </root>