XSD and plain text

Posted by Paul Knopf on Stack Overflow See other posts from Stack Overflow or by Paul Knopf
Published on 2010-12-27T03:15:55Z Indexed on 2010/12/31 8:53 UTC
Read the original article Hit count: 270

Filed under:

I have a rest/xml service that gives me the following...

<verse-unit unit-id="38009001">
    <marker class="begin-verse" mid="v38009001"/>
    <begin-chapter num="9"/><heading>Judgment on Israel&apos;s Enemies</heading>
    <begin-block-indent/>
    <begin-paragraph class="line-group"/>
    <begin-line/><verse-num begin-chapter="9">1</verse-num>The burden of the word of the <span class="divine-name">Lord</span> is against the land of Hadrach<end-line class="br"/>
    <begin-line class="indent"/>and Damascus is its resting place.<end-line class="br"/>
    <begin-line/>For the <span class="divine-name">Lord</span> has an eye on mankind<end-line class="br"/>
    <begin-line class="indent"/>and on all the tribes of Israel,<footnote id="f1">
        A slight emendation yields <i>
            For to the <span class="divine-name">Lord</span> belongs the capital of Syria and all the tribes of Israel
        </i>
    </footnote><end-line class="br"/>
</verse-unit>

I used visual studio to generate a schema from this and used XSD.EXE to generate classes that I can use to deserialize this mess into programmable stuff.

I got everything to work and it is deserialized perfectly (almost).

The problem I have is with the random text mixed throughout the child nodes. The generated verse-unit objects gives me a list of objects (begin-line, begin-block-indent, etc), and also another list of string objects that represent the bits of string throughout the xml.

Here is my schema

<xs:element maxOccurs="unbounded" name="verse-unit">
    <xs:complexType mixed="true">
        <xs:sequence>
            <xs:choice maxOccurs="unbounded">
                <xs:element name="marker">
                    <xs:complexType>
                        <xs:attribute name="class" type="xs:string" use="required" />
                        <xs:attribute name="mid" type="xs:string" use="required" />
                    </xs:complexType>
                </xs:element>
                <xs:element name="begin-chapter">
                    <xs:complexType>
                        <xs:attribute name="num" type="xs:unsignedByte" use="required" />
                    </xs:complexType>
                </xs:element>
                <xs:element name="heading">
                    <xs:complexType mixed="true">
                        <xs:sequence minOccurs="0">
                            <xs:element name="span">
                                <xs:complexType>
                                    <xs:simpleContent>
                                        <xs:extension base="xs:string">
                                            <xs:attribute name="class" type="xs:string" use="required" />
                                        </xs:extension>
                                    </xs:simpleContent>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="begin-block-indent" />
                <xs:element name="begin-paragraph">
                    <xs:complexType>
                        <xs:attribute name="class" type="xs:string" use="required" />
                    </xs:complexType>
                </xs:element>
                <xs:element name="begin-line">
                    <xs:complexType>
                        <xs:attribute name="class" type="xs:string" use="optional" />
                    </xs:complexType>
                </xs:element>
                <xs:element name="verse-num">
                    <xs:complexType>
                        <xs:simpleContent>
                            <xs:extension base="xs:unsignedByte">
                                <xs:attribute name="begin-chapter" type="xs:unsignedByte" use="optional" />
                            </xs:extension>
                        </xs:simpleContent>
                    </xs:complexType>
                </xs:element>
                <xs:element name="end-line">
                    <xs:complexType>
                        <xs:attribute name="class" type="xs:string" use="optional" />
                    </xs:complexType>
                </xs:element>
                <xs:element name="end-paragraph" />
                <xs:element name="end-block-indent" />
                <xs:element name="end-chapter" />
            </xs:choice>
        </xs:sequence>
        <xs:attribute name="unit-id" type="xs:unsignedInt" use="required" />
    </xs:complexType>
</xs:element>

WHAT I NEED IS THIS. I need the random text that is NOT surrounded by an xml node to be represented by an object so I know the order that everything is in.

I know this is complicated, so let me try to simplify it.

<field name="test_field_0">
Some text I'm sure you don't want.
<subfield>Some text.</subfield>
More text you don't want.
</field>

I need the xsd to generate a field object with items that can have either a text object, or a subfield object. I need to no where the random text is within the child nodes.

© Stack Overflow or respective owner

Related posts about xml-schema