XML 문서를 출력하는 포맷터로, 추가로 맞춤설정할 수 있는 사전 정의된 형식이 세 개 있습니다.
// Log an XML document with specified formatting options. const xml = '<root><a><b>Text!</b><b>More text!</b></a></root>'; const document = XmlService.parse(xml); const output = XmlService.getCompactFormat() .setLineSeparator('\n') .setEncoding('UTF-8') .setIndent(' ') .format(document); Logger.log(output);
메서드
| 메서드 | 반환 유형 | 간략한 설명 |
|---|---|---|
format(document) | String | 지정된 Document을 형식이 지정된 문자열로 출력합니다. |
format(element) | String | 지정된 Element 노드를 형식이 지정된 문자열로 출력합니다. |
set | Format | 포맷터가 사용해야 하는 문자 인코딩을 설정합니다. |
set | Format | 상위 요소에 상대적으로 하위 노드를 들여쓰는 데 사용되는 문자열을 설정합니다. |
set | Format | 포매터가 일반적으로 줄바꿈을 삽입할 때마다 삽입할 문자열을 설정합니다. |
set | Format | 포맷터가 XML 선언(예: <?xml version="1.0"
encoding="UTF-8"?>)을 생략해야 하는지 여부를 설정합니다. |
set | Format | 포맷터가 XML 선언에서 인코딩을 생략해야 하는지 여부를 설정합니다(예: <?xml version="1.0" encoding="UTF-8"?>의 인코딩 필드). |
자세한 문서
format(document)
format(element)
set Encoding(encoding)
포맷터가 사용해야 하는 문자 인코딩을 설정합니다. encoding 인수는 ISO-8859-1, US-ASCII, UTF-8, UTF-16과 같은 허용된 XML 인코딩이어야 합니다.
// Log an XML document with encoding that does not support certain special // characters. const xml = '<root><a><b>ಠ‿ಠ</b><b>ಠ‿ಠ</b></a></root>'; const document = XmlService.parse(xml); const output = XmlService.getRawFormat().setEncoding('ISO-8859-1').format(document); Logger.log(output);
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
encoding | String | 사용할 인코딩입니다. |
리턴
Format - 연결을 위한 포맷터입니다.
set Indent(indent)
상위 요소에 상대적으로 하위 노드를 들여쓰는 데 사용되는 문자열을 설정합니다. null 이외의 들여쓰기를 설정하면 포맷터가 모든 노드 뒤에 줄바꿈을 삽입합니다.
// Log an XML document with each child node indented four spaces. const xml = '<root><a><b>Text!</b><b>More text!</b></a></root>'; const document = XmlService.parse(xml); const output = XmlService.getCompactFormat().setIndent(' ').format(document); Logger.log(output);
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
indent | String | 사용할 들여쓰기입니다. |
리턴
Format - 연결을 위한 포맷터입니다.
set Line Separator(separator)
포매터가 일반적으로 줄바꿈을 삽입할 때마다 삽입할 문자열을 설정합니다. 사전 정의된 세 가지 포맷터는 줄바꿈을 삽입하는 조건이 서로 다릅니다. 기본 줄 구분자는 \r\n입니다.
// Log an XML document with several spaces and a pipe character in place of line // breaks. const xml = '<root><a><b>Text!</b><b>More text!</b></a></root>'; const document = XmlService.parse(xml); const output = XmlService.getRawFormat().setLineSeparator(' | ').format(document); Logger.log(output);
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
separator | String | 사용할 구분 기호입니다. |
리턴
Format - 연결을 위한 포맷터입니다.
set Omit Declaration(omitDeclaration)
포맷터가 XML 선언(예: <?xml version="1.0"
encoding="UTF-8"?>)을 생략해야 하는지 여부를 설정합니다.
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
omit | Boolean | XML 선언을 생략하려면 true, 포함하려면 false |
리턴
Format - 연결을 위한 포맷터입니다.
set Omit Encoding(omitEncoding)
포맷터가 XML 선언에서 인코딩을 생략해야 하는지 여부를 설정합니다(예: <?xml version="1.0" encoding="UTF-8"?>의 인코딩 필드).
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
omit | Boolean | true: XML 선언에서 인코딩을 생략합니다. false: 인코딩을 포함합니다. |
리턴
Format - 연결을 위한 포맷터입니다.