Processing, 類XML
中的format()
用法介紹。
用法
.format(indent)
參數
indent
(int)
-1 表示單行(並且沒有聲明),>= 0 表示縮進和換行
返回
String
說明
獲取 XML
對象並將其轉換為 String
,並按照 indent
參數的指定對其內容進行格式化。
如果 indent 設置為 -1,則返回的字符串沒有換行符、縮進和 XML
聲明。
如果 indent 設置為 0 或更大,則返回 String
並帶有換行符,並將指定數量的空格作為縮進值。意思是,如果指定 0,則沒有縮進,或者每個縮進將替換為相應數量的空格:1、2、3 等等。
例子
// The following short XML file called "mammals.xml" is parsed
// in the code below. It must be in the project's "data" folder.
//
// <?xml version="1.0"?>
// <mammals>
// <animal id="0" species="Capra hircus">Goat</animal>
// <animal id="1" species="Panthera pardus">Leopard</animal>
// <animal id="2" species="Equus zebra">Zebra</animal>
// </mammals>
XML xml;
void setup() {
xml = loadXML("mammals.xml");
//Format without line breaks and no indentation
String s = xml.format(-1);
println(s);
println(""); // Blank line
//Format with line breaks and no indentation
s = xml.format(0);
println(s);
//Format with line breaks and 5 spaces of indentation
s = xml.format(5);
println(s);
}
// Sketch prints:
//<mammals><animal id="0" species="Capra hircus">Goat</animal>
<animal id="1" species="Panthera pardus">Leopard</animal>
<animal id="2" species="Equus zebra">Zebra</animal></mammals>
//
//<?xml version="1.0" encoding="UTF-8"?>
//<mammals>
//<animal id="0" species="Capra hircus">Goat</animal>
//<animal id="1" species="Panthera pardus">Leopard</animal>
//<animal id="2" species="Equus zebra">Zebra</animal>
//</mammals>
//
//<?xml version="1.0" encoding="UTF-8"?>
//<mammals>
// <animal id="0" species="Capra hircus">Goat</animal>
// <animal id="1" species="Panthera pardus">Leopard</animal>
// <animal id="2" species="Equus zebra">Zebra</animal>
//</mammals>
有關的
相關用法
- Processing XML.addChild()用法及代碼示例
- Processing XML.getString()用法及代碼示例
- Processing XML.setString()用法及代碼示例
- Processing XML.listChildren()用法及代碼示例
- Processing XML.getInt()用法及代碼示例
- Processing XML.toString()用法及代碼示例
- Processing XML.getName()用法及代碼示例
- Processing XML.setFloat()用法及代碼示例
- Processing XML.removeChild()用法及代碼示例
- Processing XML.setContent()用法及代碼示例
- Processing XML.getChild()用法及代碼示例
- Processing XML.getParent()用法及代碼示例
- Processing XML.getFloat()用法及代碼示例
- Processing XML.setInt()用法及代碼示例
- Processing XML.getChildren()用法及代碼示例
- Processing XML.getAttributeCount()用法及代碼示例
- Processing XML.listAttributes()用法及代碼示例
- Processing XML.getFloatContent()用法及代碼示例
- Processing XML.getContent()用法及代碼示例
- Processing XML.hasChildren()用法及代碼示例
- Processing XML.hasAttribute()用法及代碼示例
- Processing XML.setName()用法及代碼示例
- Processing XML用法及代碼示例
- Processing FFT用法及代碼示例
- Processing SawOsc.pan()用法及代碼示例
注:本文由純淨天空篩選整理自processing.org大神的英文原創作品 XML.format()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。