2010-12-27 2 views
2

私は私に次のことを与え、残り/ XMLサービスを持っている...XSDとプレーンテキスト

<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> 

私はこれからスキーマを生成するためのVisual Studioを使用している私ができるクラスを生成するためにXsd.exeではを使用しましたこの混乱をデシリアライズしてプログラム可能なものにする。

私はすべての作業を完了しており、完全に(ほぼ)デシリアライズされています。

問題は、子ノード全体にランダムなテキストが混在することです。生成されたverse-unitオブジェクトは、オブジェクトのリスト(begin-line、begin-block-indentなど)、およびxml全体の文字列のビットを表す別の文字列オブジェクトのリストを提供します。ここで

は私のスキーマは、私は必要なもの

<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> 

ですTHIS IS。オブジェクトによって表されるxmlノードに囲まれていないランダムなテキストが必要です。すべてが入っている順序を知っています。

私はこれが複雑なので分かります。

<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>

私は、テキストオブジェクト、またはサブフィールドオブジェクトのいずれかを持つことができるアイテムでフィールドオブジェクトを生成するXSDを必要としています。私は、ランダムなテキストが子ノード内のどこにある必要があります。

答えて

0

さて、あなたの問題はここから:<begin-line class="lineclass">しかし:

<xs:element name="begin-line"> 
    <xs:complexType> 
     <xs:attribute name="class" type="xs:string" use="optional" /> 
    </xs:complexType> 
</xs:element> 

これが意味することは、「開始行」タイプがタグはそうのような属性クラスを持つことができることを意味(クラスと呼ばれる属性を持っているということです単にあなたが得るすべてが文字列であることを意味タイプxs:stringある

これがオプションであれば、私も知りませんが、あなたのXMLは、例えば、このラインのようなタグを閉じているようにすることができれば:。 <begin-line class="indent"/>and Damascus is its resting place.<end-line class="br"/>

私はすべての「行」のタグが適切に閉鎖されたならば、XSDジェネレータは、「開始行」の中にあるものを導出しようとして良い時間を持っているかもしれないと信じている <begin-line class="indent"/>and Damascus is its resting place.</begin-line class="br">

XMLタグ:

XMLは次のようにする必要があります。実際にこれが可能ならばbegin-linelinebegin-chapterからchapterに変更すると、XMLをもっと読みやすくすることができます。

コードを更新できない場合は、文字列そのものを試してみる必要があります。私は詩に純粋なHTMLが含まれているかどうかは分かりませんが、そうであればbegin-line要素の中の文字列をXMLとして解析し、ライブラリを使って値とノードの間をジャンプします(前に文字列の周りにそれを解析しようとしている)。

幸運:)

+0

残念ながら、このXMLは私が扱う必要があります。 デシリアライズする前に、マジックをXMLに置き換えて正規表現文字列を実行することについてどう思いますか?私はすべての自己閉鎖タグを開始タグに変え、すべてのタグをタグに変えることを考えていました。どう思いますか? –

+0

あなたのサンプルのXMLの大きさに応じて、しばらく時間がかかることがあります。 – Spence

関連する問題