2014-01-22 8 views
3

다음 XML 태그가 많은데Linux에서 XML 문서의 형식을 지정하는 방법

<SERVICE> 
<NAME> 
sh_SEET15002GetReKeyDetails 
</NAME> 
<ID>642</ID> 
</SERVICE> 

이 형식을 다음과 같이 지정하고자합니다. 나는 xmllint를 사용하여 시도했지만 그것은 나를 위해 작동하지 않습니다. 도움을주십시오.

<SERVICE> 
<NAME>sh_SEET15002GetReKeyDetails</NAME> 
<ID>642</ID> 
</SERVICE> 
+0

: 네 개의 공간 들여 쓰기를 들어

export XMLLINT_INDENT='echo -e '\t'' 

? – Reuben

답변

6

Eclipse XML Source Editor을 프로그래밍 할 필요가 없습니다. 이걸 좀 봐 answer

그런데 xmllint -format -recover nonformatted.xml > formated.xml을 사용해 보셨습니까?

편집 :

XMLStarlet Command Line XML Toolkit을 시도 할 수 있습니다. 탭 들여 쓰기를 들어

5. Formatting XML documents 
==================================================== 

xml fo --help 
XMLStarlet Toolkit: Format XML document 
Usage: xml fo [<options>] <xml-file> 
where <options> are 
    -n or --noindent   - do not indent 
    -t or --indent-tab   - indent output with tabulation 
    -s or --indent-spaces <num> - indent output with <num> spaces 
    -o or --omit-decl   - omit xml declaration <?xml version="1.0"?> 
    -R or --recover    - try to recover what is parsable 
    -D or --dropdtd    - remove the DOCTYPE of the input docs 
    -C or --nocdata    - replace cdata section with text nodes 
    -N or --nsclean    - remove redundant namespace declarations 
    -e or --encode <encoding> - output in the given encoding (utf-8, unicode...) 
    -H or --html    - input is HTML 
    -h or --help    - print help 
+0

예. 같은 명령을 사용했지만이 경우에는 작동하지 않습니다. 가능한 경우 쉘 스크립트 나 xslt가 필요할 수도 있습니다. – user2693992

+0

EDIT를 확인하고 성공했는지 여부를 알려줍니다. – Reuben

+0

xml fo --help LPX-00202 : "fo"를 열 수 없습니다 (오류 200) – user2693992

4
xmllint -format -recover nonformatted.xml > formated.xml 

: 당신은 또는 프로그래밍없이 포맷 할

export XMLLINT_INDENT=\ \ \ \