首页 > 文档 > parseXML()获取XML
2017
07-14

parseXML()获取XML

3-13.parseXML()

Name(名称):

Examples(例子):

String data = “<mammals><animal>Goat</animal></mammals>”;

 

void setup() {

XML xml = parseXML(data);

if (xml == null) {

println(“XML could not be parsed.”);

} else {

XML firstChild = xml.getChild(“animal”);

println(firstChild.getContent());

}

}

 

// Sketch prints:

// Goat

Description(描述):Takes a String, parses its contents, and returns an XML object. If the String does not contain XML data or cannot be parsed, a null value is returned.

获取字符串,解析其内容,并返回一个XML对象。 如果该字符串不包含XML数据或不能解析,则返回一个空值。

parseXML() is most useful when pulling data dynamically, such as from third-party APIs. Normally, API results would be saved to a String, and then can be converted to a structured XML object using parseXML(). Be sure to check if null is returned before performing operations on the new XML object, in case the String content could not be parsed.

当动态拉动数据时,parseXML()是最有用的,例如来自第三方API。 通常,API结果将被保存到String中,然后可以使用parseXML()将其转换为结构化的XML对象。 在对新的XML对象执行操作之前,请确保检查是否返回null,以防无法解析String内容。

If your data already exists as an XML file in the data folder, it is simpler to use loadXML().

如果您的数据已经作为数据文件夹中的XML文件存在,那么使用loadXML()就更简单了。

Syntax(语法): parseXML(xmlString)

parseXML(xmlString, options)

Parameters (参数):xmlString——the content to be parsed as XML要解析为XML的内容

Returns(返回值):XML

 

Related(相关函数):XML
loadXML()
saveXML()



最后编辑:
作者:卡萨布兰卡
这个作者貌似有点懒,什么都没有留下。

留下一个回复

你的email不会被公开。