简体   繁体   English

解析列表 <String> 使用XML模式转换为XML

[英]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. 寻找一种简单的方法来分析字符串列表(或2d array [string1,string2]),其中字符串1是名称,字符串2是内容。

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. 结果应为.xml,仅包含在xml模式名称与string1相同的所有位置填充的字符串2的数据。

<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<String>看起来像这样:

LIST 1 : {noteCadre1, noteCadre2, .... , infoResidence.lieu.1 , infoResidence.dateDebut.1 , infoResidence.dateFin.1 , infoResidence.lieu.2 , infoResidence.dateDebut.2 , ... 清单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, ..... } 清单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. 您不能仅使用XML Schema来做到这一点:XML Schema是关于验证XML文档而不是解析。

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. 为此,您需要添加第一步,将输入文档(字符串列表)转换为目标XML表示形式。

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. 使用任何编程语言(包括XSLT 2.0)似乎都非常容易实现,但这显然超出了XML模式语言的范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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