simplexml icon indicating copy to clipboard operation
simplexml copied to clipboard

Complex types with Mixed Content

Open foo4u opened this issue 8 years ago • 2 comments

XML is allowed to contain mixed types (types with elements and text nodes), for example:

<letter>
  Dear Mr.<name>John Smith</name>.
  Your order <orderid>1032</orderid>
  will be shipped on <shipdate>2001-07-13</shipdate>
  Thank you for your business.
</letter>

The schema for this element letter would be as follows:

<xs:element name="letter">
  <xs:complexType mixed="true">
    <xs:sequence>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="orderid" type="xs:positiveInteger"/>
      <xs:element name="shipdate" type="xs:date"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

I'm having trouble figuring out how to use Simple XML to read such a complex type correctly without resorting to accessing the underlying parser.

The example was lifted from W3 Schools.

foo4u avatar Mar 07 '16 17:03 foo4u

Actually, I should clarify that I can do it with a converter, but whitespace handling is different depending on the underlying parser. The Oracle supplied Stax parser is different than the pull parser on Android, for example.

foo4u avatar Mar 07 '16 17:03 foo4u

Hi, I think that would be tricky, you could use CDATA blocks, but if you have no control of the XML you would need to modify the library itself. Have a look at the EventReader implementations, I think you could make a fairly simple modification there. Niall

  From: Scott Rossillo <[email protected]>

To: ngallagher/simplexml [email protected] Sent: Monday, 7 March 2016, 17:40 Subject: Re: [simplexml] Complex types with Mixed Content (#6)

Actually, I should clarify that I can do it with a converter, but whitespace handling is different depending on the underlying parser. The Oracle supplied Stax parser is different than the pull parser on Android, for example.— Reply to this email directly or view it on GitHub.

ngallagher avatar Mar 07 '16 20:03 ngallagher