0

ここに、属性値のフェッチを担当するコードがあります。

currPost.Body = reader.getAttributeValue("", "Body");

だから、Bodyまさに私の問題が基づいている属性です。

XML ファイルは SQL Server ダンプを表し、次のような形式になっています。

<?xml version="1.0" encoding="utf-8"?>
<posts>
<row Id="1" PostTypeId="1" AcceptedAnswerId="65" CreationDate="2011-05-24T19:28:37.853" Score="13" ViewCount="964" Body="&lt;p&gt;Sehr viele Märchen beginnen auf Deutsch mit &quot;Es war einmal&quot;, aber ich kenne auch ein Märchen, das anfängt mit &quot;Zu der Zeit, als das Wünschen noch geholfen hat ...&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Gibt es noch andere Beginnformeln und wenn ja, kann man diese dem geographischen Ursprung der Märchen zuordnen?&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Many German fairy tales open with&#xA;  &quot;Es war einmal&quot;, but some start with&#xA;  &quot;Zu der Zeit, als das Wünschen noch&#xA;  geholfen hat ...&quot;.&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;Are there any other common&#xA;  introductions? If so, is there a correlation between their use and the geographic origin of the story?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="4" LastEditorUserId="2" LastEditDate="2011-05-25T05:39:54.580" LastActivityDate="2011-05-25T11:56:08.270" Title="Gibt es andere übliche Märchenbeginnformeln neben &quot;es war einmal&quot;?" Tags="&lt;regional&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="4" />

問題自体は、「ボディ」値を取得すると、多くの文字/記号が欠落している短縮された文字列が常に取得されることです。

値を見てくださいBody。それは

Body="&lt;p&gt;Sehr viele Märchen beginnen auf Deutsch mit &quot;Es war einmal&quot;, aber ich kenne auch ein Märchen, das anfängt mit &quot;Zu der Zeit, als das Wünschen noch geholfen hat ...&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Gibt es noch andere Beginnformeln und wenn ja, kann man diese dem geographischen Ursprung der Märchen zuordnen?&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Many German fairy tales open with&#xA;  &quot;Es war einmal&quot;, but some start with&#xA;  &quot;Zu der Zeit, als das Wünschen noch&#xA;  geholfen hat ...&quot;.&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;Are there any other common&#xA;  introductions? If so, is there a correlation between their use and the geographic origin of the story?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;"

だから、私がちょうど印刷すると、System.out.println() これだけが得られます

<p>Sehr viele Märchen beginnen auf Deutsch mit "Es war einmal", aber ich kenne auch ein Märchen, das anfängt mit "Zu der Zeit, als das Wünschen noch geholfen hat ...".</p>

ご覧のとおり、Body値には html タグが含まれています。これが問題になる可能性はありますか?そして、どうすればいいですか?

それとも、他の解決策がありますか?

どうもありがとう!

4

1 に答える 1

1

&#xA;&#xA;問題はXMLにあると思われます。それは U+000A、つまり「改行」 (2 回) です。XML を完全に取り除くことで、これが問題であることを確認できます。これが何をするか見てください:

 System.out.println("Line 1\nLine2\nLine 3");

コンソールによっては、複数の行に表示される場合があります。それは、XML からの文字列にも起こると私が期待していることです。私の推測では、属性テキストの先頭から始まる行しか見ていないか、コンソールが複数行の出力をサポートしていません。いずれにせよ、上記の簡単なテストにより、何が期待できるかがわかります。

于 2014-10-10T19:40:54.363 に答える