开发者

Standard way to embed newlines into xml

I have some xml like this:

<animal name="Bow Wow" type="dog">
    <birthDate>May 17,2001</birthDate>
    <descirption>Bla bla bla bla</description>
</animal>

The xml is being processed and displayed on the screen.

I need to provide a longer multi-paragraph description of the dog but I am running into some problems.

If I write my xml like this:

<animal name="Bow Wow" type="dog">
    <birthDate>May 17,2001</birthDate>
    <descirption>
          p1: Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla

          p2: Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla

          p3: Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    </description>
</animal>

Then when the xml is printed to the screen it is printed like this:

              p1: Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla 
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla

              p2: Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla 
bla bla bla bla bla bla bla bla bla bla bla bla bla bla

              p3: Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla 
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla

I would like the description to be printed like this (without the leading tabs):

p1: Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla 
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla

p2: Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla 
bla bla bla bla bla bla bla bla bla bla bla

p3: Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla 
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla

Is there a reasonable solution to this problem? I was thinking that one thing I could do would be to put all the text on one line like this:

    <descirption>p1: Bla bla bla bla bla bla bla bla bla bla bla bla bla b开发者_Python百科la bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla <NEWLINE/>NEWLINE/>p2: Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla<NEWLINE/>NEWLINE/>p3: Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</description>

I am not sure if there is a standard xml new line tag though. I know that you can encode an & with & is there something like this for new line? Is there a standard way to deal with this issue?


XML whitespace handling is a big problem. Your DOM will have settable options which affect how it works, but the upshot is:

The easiest way to solve the problem is to ignore whitespace and use a tag of your own make. I use <br /> for newlines, then convert them to CRLF for display.

If using XSLT you will need to make use of <xsl:text> tags wherever you need text to make sure whitespace is handled how you want.


I would like the description to be printed like this (without the leading tabs)

Remove the leading tabs from your source

<animal name="Bow Wow" type="dog">
    <birthDate>May 17,2001</birthDate>
    <descirption>
p1: Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla

p2: Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla

p3: Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    </description>
</animal>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜