2016-12-13 9 views
1
나는 위의 읽을 때 나는 YamlReader (yamlbeans.YamlReader)와 YAML 파일

아래로 YAML

- tag: xyz 
    description: | 
    This is multi-line comment and I want to preserve 
    leading white spaces and new line 

을 읽고있다

을 읽는 동안 최고의 공백을 보존하는 방법 : 그것은 아래에 제공

String descr = tag.get("description"); 

출력 :

This is multi-line comment and I want to preserve 
leading white spaces and new line 

그러나 나는 선행 공백을 보존하고 싶습니다.

- tag: xyz 
    description: |1 
    This is a multi-line comment and I want to preserve 
    leading white spaces and new line 

다음 블록 스칼라 추가 들여 쓰기 하나 공간이 것이라는 1 주 (현재의 들여 쓰기 수준 이외에)이 줄 것이다 :

This is a multi-line comment and I want to preserve 
    leading white spaces and new line 
+0

YAML 지정에 따르면 YAML 파일의 키 설명에 대한 값에 선행 공백이 없습니다. 그러므로 보존 할 것이 없습니다. – Anthon

답변

2

는 들여 쓰기 표시기를 사용하여

위에서 보았 듯이 블록 스칼라의 한 들여 쓰기 공간 뒤에있는 두 개의 공백이 보존됩니다. 들여 쓰기 표시기로 한 자리 숫자를 사용할 수 있습니다.

줄 바꿈 줄 바꿈 문자를 유지하려면 |1+을 사용하십시오. 여기에서 +은 YAML에게 줄 바꿈 줄 문자를 보존하도록 지시합니다.