3-10.loadXML()
Name(名称):
Examples(例子):
// 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”);
XML[] children = xml.getChildren(“animal”);
for (int i = 0; i < children.length; i++) {
int id = children[i].getInt(“id”);
String coloring = children[i].getString(“species”);
String name = children[i].getContent();
println(id + “, ” + coloring + “, ” + name);
}
}
// Sketch prints:
// 0, Capra hircus, Goat
// 1, Panthera pardus, Leopard
// 2, Equus zebra, Zebra
Description(描述):Reads the contents of a file or URL and creates an XML object with its values. If a file is specified, it must be located in the sketch’s “data” folder. The filename parameter can also be a URL to a file found online.
读取文件或URL的内容,并使用其值创建一个XML对象。 如果指定了文件,它必须位于草图的”数据”文件夹中。 文件名参数也可以是在线查找的文件的URL。
All files loaded and saved by the Processing API use UTF-8 encoding. If you need to load an XML file that’s not in UTF-8 format, see the developer’s reference for the XML object.
Processing API加载和保存的所有文件都使用UTF-8编码。 如果您需要加载不是UTF-8格式的XML文件,请参阅开发人员对XML对象的引用。
Syntax(语法): loadXML(filename)
Parameters (参数):filename——name of a file in the data folder or a URL.
数据文件夹中的文件名或URL。
Returns(返回值):XML
Related(相关函数):XML
parseXML()
saveXML()
loadBytes()
loadStrings()
loadTable()
- 本文固定链接: http://iprocessing.cn/2017/07/14/loadxml读取xml对象/
- 转载请注明: 卡萨布兰卡 于 Processing编程艺术 发表