2016-06-22 25 views
0

私はC#を使用してxmlファイル内のテキストを読み込んで抽出する良い方法を探しています。私はここで-w:t xml:space="preserve- XXXX -/w:t-C#を使用してこの種のXMLファイルを読み取る方法は?

内のテキストを連結する

は、ファイルのサンプルです:

<w:body> 
    <w:sdt xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"> 
     <w:sdtPr> 
     <w:rPr> 
      <w:b /> 
      <w:bCs /> 
      <w:noProof /> 
     </w:rPr> 
     <w:alias w:val="Business Rule" /> 
     <w:tag w:val="urn:ILOG.RuleDoc.3:Rule_a9e5674c-7145-4bfb-af53-524543e98358" /> 
     <w:id w:val="8959571" /> 
     </w:sdtPr> 
     <w:sdtContent> 
     <w:p w:rsidR="00711D98" w:rsidRDefault="00711D98" w:rsidP="00711D98"> 
      <w:pPr> 
      <w:pStyle w:val="Rule" /> 
      <w:rPr> 
       <w:b /> 
       <w:bCs /> 
       <w:noProof /> 
      </w:rPr> 
      </w:pPr> 
     </w:p> 
     <w:p w:rsidR="00711D98" w:rsidRPr="00C95F62" w:rsidRDefault="00711D98" w:rsidP="00711D98"> 
      <w:sdt> 
      <w:sdtPr> 
       <w:rPr> 
       <w:rStyle w:val="Heading3Char" /> 
       <w:noProof /> 
       </w:rPr> 
       <w:alias w:val="Name" /> 
       <w:tag w:val="urn:ILOG.RuleDoc.3:RuleProperty" /> 
       <w:id w:val="7323368" /> 
       <w:dataBinding w:prefixMappings="xmlns:ns0='http://schemas.ilog.com/Rules/3.0/RuleDocumentData' xmlns:ns1='http://schemas.ilog.com/Rules/1.1/Properties' xmlns:ns2='urn:Intellinsure'" w:xpath="//ns0:ActionRule/ns0:Properties/ns1:Uuid[.='a9e5674c-7145-4bfb-af53-524543e98358']/../ns1:Name" w:storeItemID="{00000000-0000-0000-0000-000000000000}" /> 
       <w:text /> 
      </w:sdtPr> 
      <w:sdtContent> 
       <w:r> 
       <w:rPr> 
        <w:rStyle w:val="Heading3Char" /> 
       </w:rPr> 
       <w:t>New Rule 9</w:t> 
       </w:r> 
      </w:sdtContent> 
      </w:sdt> 
     </w:p> 
     <w:p w:rsidR="00711D98" w:rsidRPr="0032004A" w:rsidRDefault="00711D98" w:rsidP="00711D98"> 
      <w:pPr> 
      <w:pStyle w:val="Rule" /> 
      </w:pPr> 
     </w:p> 
     <w:sdt> 
      <w:sdtPr> 
      <w:alias w:val="Rule Body" /> 
      <w:tag w:val="urn:ILOG.RuleDoc.3:RuleBody" /> 
      <w:id w:val="9275215" /> 
      </w:sdtPr> 
      <w:sdtContent xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"> 
      <w:p> 
       <w:pPr> 
       <w:pStyle w:val="RuleBody" /> 
       </w:pPr> 
       <w:r> 
       <w:rPr> 
        <w:rStyle w:val="RuleBodyNormal" /> 
       </w:rPr> 
       <w:t xml:space="preserve">definitions</w:t> 
       </w:r> 
      </w:p> 
      <w:p> 
       <w:pPr> 
       <w:pStyle w:val="RuleBody" /> 
       </w:pPr> 
       <w:r> 
       <w:tab /> 
       </w:r> 
       <w:r> 
       <w:rPr> 
        <w:rStyle w:val="RuleBodyNormal" /> 
       </w:rPr> 
       <w:t xml:space="preserve">set 'subscriber' to an actor in the subscribers to "Contract-Name" in 'the request' ;</w:t> 
       </w:r> 
      </w:p> 
      <w:p> 
       <w:pPr> 
       <w:pStyle w:val="RuleBody" /> 
       </w:pPr> 
       <w:r> 
       <w:tab /> 
       </w:r> 
       <w:r> 
       <w:rPr> 
        <w:rStyle w:val="RuleBodyNormal" /> 
       </w:rPr> 
       <w:t xml:space="preserve">set 'excludedSubscribersList' to the excluded subscribers to "Contract-Name" in 'the request' ;</w:t> 
       </w:r> 
      </w:p> 

それはのようなものを与える必要があります:アクターへ

定義
セットの加入者を契約者の契約名へ の除外された加入者にexcludedSubscribersListを '要求'に設定します。

ありがとうございました。 XmlReaderを使用して

答えて

0

:あなたの助けを

definitions 
set 'subscriber' to an actor in the subscribers to "Contract-Name" in 'the request' ; 
set 'excludedSubscribersList' to the excluded subscribers to "Contract-Name" in 'the request' ; 
+0

感謝を:与え

StringBuilder content = new StringBuilder(); // open the file using (Stream file = File.OpenRead("test.xml")) { XmlReaderSettings settings = new XmlReaderSettings(); //must use this to declare the 'w' namespace NameTable nt = new NameTable(); XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt); nsmgr.AddNamespace("w", "urn:http://schemas.openxmlformats.org/wordprocessingml/2006/main"); XmlParserContext ctx = new XmlParserContext(null, nsmgr, null, XmlSpace.None); using (XmlReader reader = XmlReader.Create(file, settings, ctx)) { while (reader.Read()) { // parse content of 't' elments and add them to the string builder if (reader.NodeType == XmlNodeType.Element && reader.LocalName.Equals("t")) { if ("preserve".Equals(reader.GetAttribute("xml:space"))) { reader.ReadStartElement(); content.Append(reader.ReadContentAsString()); content.AppendLine(); } } } } } 

。 もう少し質問をすることができます: 属性xml:space = "preserve"がないので、新しいルール9を避けるために離れていますか? この行の目的は次のとおりです。nsmgr.AddNamespace( "w"、 "urn:http://mynamespace.owner.com"); ? ありがとうございます。 –

+0

xml属性のフィルタで回答を更新しました。提供されたXMLがうまく構成されていないので、名前空間 'w'を指定する必要があります。 ''は 'にする必要があります。 '。この宣言がなければ、 'body'要素に対して名前空間' w'が宣言されていないため、パーサはExceptionを発生させます。 –

関連する問題