Program Tip

XML에 새 줄 / 바꿈 태그 추가

programtip 2020. 11. 3. 18:53
반응형

XML에 새 줄 / 바꿈 태그 추가


이 질문에 이미 답변이 있습니다.

XML 내의 코드에 새 줄 / 바꿈을 추가하려고 시도했지만 실패했습니다.

지금까지 시도했습니다.

<br />
<br> 



다음은 내가 작업중인 코드의 샘플입니다. 
코드 내에서 구분이있는 위치를 표시하기 위해 " "를 포함했습니다 .

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="dummy.xsl"?>
  <item>
     <summary>Tootsie roll tiramisu macaroon wafer carrot cake.       
               &#xA; Danish topping sugar plum tart bonbon caramels cake.
     </summary>
  </item>

새 줄 XML

XML로

  1. 캐리지 리턴 :&#xD;
  2. 줄 바꿈 :&#xA;

또는 CDATA로 @dj_segfault가 제안한 것처럼 시도하십시오 (그의 답변 참조).

 <![CDATA[Tootsie roll tiramisu macaroon wafer carrot cake.                       
            Danish topping sugar plum tart bonbon caramels cake.]]>

멋진 것은 필요하지 않습니다. 다음은 새 줄을 포함합니다 (실제로는 2 개).

<summary>Tootsie roll tiramisu macaroon wafer carrot cake.       
         Danish topping sugar plum tart bonbon caramels cake.
</summary>

질문은 왜이 줄 바꿈이 원하는 효과를 갖지 않는지입니다. 이것이 XML 수신자가 실제로 무엇을하고 있는지에 대한 질문입니다. 예를 들어 수신자가 HTML로 번역하고 HTML이 브라우저에 표시되는 경우 새 줄은 브라우저에 의해 공백으로 변환됩니다. 처리 파이프 라인에 대해 알려 주셔야합니다.


이 질문에 대한 해결책은 다음과 같습니다.

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="dummy.xsl"?>
  <item>
     <summary>
        <![CDATA[Tootsie roll tiramisu macaroon wafer carrot cake. <br />      
                 Danish topping sugar plum tart bonbon caramels cake.]]>
     </summary>
  </item>

<br />안쪽 에 추가하면 <![CDATA]]>줄이 끊어져 새 줄이 만들어집니다!


아마도 Windows를 사용하고 있으므로 새 줄은 CR + LF(캐리지 리턴 + 줄 바꿈)입니다. 따라서 해결책은 다음과 같습니다.

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="dummy.xsl"?>
  <item>
     <summary>Tootsie roll tiramisu macaroon wafer carrot cake.&#13;&#10;Danish topping sugar plum tart bonbon caramels cake.
     </summary>
  </item>

Linux의 경우 LFMac OS 전용 CR입니다.

문제에서 Linux 방식을 보여주었습니다.


이 솔루션은 저에게 효과적이었습니다.

<summary>Tootsie roll tiramisu macaroon wafer carrot cake. &#xD;Danish topping sugar plum tart bonbon caramels cake.</summary>

두 줄로 된 텍스트가 있습니다.

이것은 XmlReader.Read 메서드를 사용하여 저에게 효과적이었습니다.


공백을 유지하려면 CDATA 블록넣어야 할 것입니다.

<?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="dummy.xsl"?>   
   <item>      
      <summary>
         <![CDATA[Tootsie roll tiramisu macaroon wafer carrot cake.                       
            Danish topping sugar plum tart bonbon caramels cake.]]>
      </summary>   
   </item> 

CDATA를 사용하지 않고

<xsl:value-of select="'&#xA;'" />

큰 따옴표와 작은 따옴표에 유의하십시오.

xml 일명 텍스트를 작성하지 않는 경우 특히 유용합니다. <xsl:output method="text" />


줄 바꿈을 제공하는 가장 쉬운 방법은 다음을 수행하는 것입니다.
1> CSS에 다음을 추가합니다.- e{display:block}
2> 이제 줄 바꿈을 원하는 위치에 다음을 입력합니다.

<e></e>

XML에서 줄 바꿈을 수행하는 방법은 &#xA;

내 XML 레이아웃을 디자인하고 TextView를 사용할 때 Eclipse IDE에서 나를 위해 일했습니다.


고정 길이 필드 형식을 개발해야 할 때 동일한 문제가 발생했습니다.

일반적으로 바이너리 파일에는 줄 구분 기호를 사용하지 않지만 어떤 이유로 고객은 레코드 사이의 구분 기호로 줄 바꿈을 추가하기를 원했습니다. 그들은 설정

< record_delimiter value="\n"/ >

but this didn't work as records got two additional characters:
< record1 > \n < record2 > \n.... and so on.

Did following change and it just worked.

< record_delimiter value="\n"/> => < record_delimiter value="&#xA;"/ >

After unmarshaling Java interprets as new line character.


Wanted to add my solution:

&lt; br/ &gt;

which is basically the same as was suggested above
In my case I had to use &lt for < and &gt for > Simply putting <br /> did not work.


just simply press enter it make a break

<![CDATA[this is
my text.]]>

This can be addressed simple by CSS attribute:

XML: <label name="pageTac"> Hello how are you doing? Thank you I'm Good</label>

CSS

.pageText{
white-space:pre !important; // this wraps the xml text.}

HTML / XSL

<tr>
        <td class="pageText"><xsl:value-of select="$Dictionary/infolabels/label[@name='pageTac']" />
            </td></tr>

(Using system.IO)

You can simply use \n for newline and \t in front of the string to indent it.

For example in c#:

public string theXML() {
    string xml = "";
    xml += "<Scene>\n";
    xml += "\t<Character>\n";


    xml += "\t</Character>\n";
    xml += "</Scene>\n";
    return xml;
}

This will result in the output: http://prntscr.com/96dfqc

참고URL : https://stackoverflow.com/questions/10917555/adding-a-new-line-break-tag-in-xml

반응형