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价值。这是

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,或“换行”(两次)。您可以通过完全去掉 XML 来验证这是否是问题所在。看看这是做什么的:

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

根据您的控制台,它可能出现在多行上。这也是我希望 XML 中的字符串发生的情况。我的猜测是您只查看了以属性文本开头的行,或者您的控制台不支持多行输出。无论哪种方式,上面的快速测试都应该让您了解会发生什么。

于 2014-10-10T19:40:54.363 回答