simplexml
simplexml copied to clipboard
Complex types with Mixed Content
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.
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.
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.