简体   繁体   中英

Parsing List<String> into XML using an XML Schema

Looking for an easy way to parse a list of strings (or 2d array[string1,string2]) where string 1 is the name and string 2 is the content.

The result should be an .xml containing only the data of string 2 filled in in all the places where the names of the xml schema are the same as string1.

<xs:include schemaLocation="common.xsd"/>

<xs:complexType name="part1Type">
    <xs:all>
        <xs:element name="noteCadre1" type="string5000Type" minOccurs="0"/>
        <xs:element name="noteCadre2" type="string5000Type" minOccurs="0"/>
        <xs:element name="noteCadre3" type="string5000Type" minOccurs="0"/>
        <xs:element name="noteCadre4" type="string5000Type" minOccurs="0"/>
        <xs:element name="noteCadre5" type="string5000Type" minOccurs="0"/>
        <xs:element name="noteCadre6" type="string5000Type" minOccurs="0"/>
        <xs:element name="noteCadre7" type="string5000Type" minOccurs="0"/>
        <xs:element name="noteCadre8" type="string5000Type" minOccurs="0"/>
        <xs:element name="noteCadre9" type="string5000Type" minOccurs="0"/>
        <xs:element name="noteCadre10" type="string5000Type" minOccurs="0"/>
        <xs:element name="noteCadre11" type="string5000Type" minOccurs="0"/>
        <xs:element name="noteCadre12" type="string5000Type" minOccurs="0"/>


        <xs:element name="infoResidence" type="home2Type" minOccurs="0"/>

<xs:complexType name="homeType">
    <xs:sequence>
        <xs:element name="lieu" type="string150Type"/>
        <xs:element name="dateDebut" type="xs:date" minOccurs="0"/>
        <xs:element name="dateFin" type="xs:date" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>

<xs:complexType name="home2Type">
    <xs:sequence>
        <xs:element name="item" type="homeType" maxOccurs="2"/>
    </xs:sequence>
</xs:complexType>

The List<String> looks like this:

LIST 1 : {noteCadre1, noteCadre2, .... , infoResidence.lieu.1 , infoResidence.dateDebut.1 , infoResidence.dateFin.1 , infoResidence.lieu.2 , infoResidence.dateDebut.2 , ...

LIST 2 : {dataCadre1, dataCadre2, .... , Street 100, 01/01/20005, 25/03/2005, ..... }

Any help would be appreciated; browsed the web for a couple of days without any succes..

You can't do that using only XML Schema: XML Schema is about validating XML documents and not about parsing.

To do this kind of things you need to add a first step that transforms your input document (the list of strings) into your target XML representation.

This seems quite easy to achieve using any programming language (including XSLT 2.0) but this is clearly out of the scope of XML schema languages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM