0

Here I have some code responsible for fetching the attribute value:

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

so, Body is the very attribute my problem is based on.

My XML file represents SQL Server dump and is in the form as follows:

<?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" />

The problem itself is that when I retrieve the "Body" value - I always get a shortened string which is missing lot of characters/symbols.

Take a look at the Body value. It is

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

So, when I just print with System.out.println() I get only this

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

As you can see - the Body value contains html tags. Can this be the problem? And how do I go about it?

Or maybe there are any other resolutions?

Thanks a lot!

1 Answer 1

1

I suspect the problem is the &#xA;&#xA; in your XML. That's U+000A, or "line feed" (twice). You can validate that this is the problem by taking the XML out of it entirely. See what this does:

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

Depending on your console, that may appear on multiple lines. That's what I'd expect to happen to your string from the XML as well. My guess is either you only looked at the line starting with the start of your attribute text, or your console doesn't support multiline output. Either way, the quick test above should give you an idea of what to expect.

Sign up to request clarification or add additional context in comments.

2 Comments

Oops. Seems like I've missed something. My output contains all the attribute value data well formatted. It just jumps to the next line. So, thank you very much for your help! Btw, how did you recognized those symbols (&#xA;&#xA;) ? Do you use any software to detect them or you know them from memory?
@AlexHerrmann: Well, &#x...; is an XML entity reference specified as a Unicode value in hex, and U+000A is line-feed. I always need to check to see which of U+000A and U+000D is line-feed and which is carriage-return, but the rest I knew :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.