首页 > 文档 > XML XML对象
2017
07-20

XML XML对象

Name

XML XML对象

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

XML is a representation of an XML object, able to parse XML code. Use loadXML() to load external XML files and create XML objects.

Only files encoded as UTF-8 (or plain ASCII) are parsed properly; the encoding parameter inside XML files is ignored.

xml xml 对象的一种表示形式, 能够解析 xml 代码。使用 loadXML () 加载外部 xml 文件并创建 xml 对象。

 

只有编码为 UTF-8 (或纯 ascii) 的文件才能正确解析;xml 文件中的编码参数被忽略。

Methods

getParent()

Gets a copy of the element’s parent

获取元素的父级的副本

getName()

Gets the element’s full name

获取元素的全名

setName()

Sets the element’s name

设置元素的名称

hasChildren()

Checks whether or not an element has any children检查元素是否有子级

listChildren()

Returns the names of all children as an array将所有子级的名称作为数组返回

getChildren()

Returns an array containing all child elements返回一个包含所有子元素的数组

getChild()

Returns the child element with the specified index value or path

返回具有指定索引值或路径的子元素

addChild()

Appends a new child to the element

将新子项追加到元素

removeChild()

Removes the specified child移除指定的子级

getAttributeCount()

Counts the specified element’s number of attributes

计算指定元素的属性个数

listAttributes()

Returns a list of names of all attributes as an array将所有属性的名称列表作为数组返回

hasAttribute()

Checks whether or not an element has the specified attribute

检查元素是否具有指定的属性

getString()

Gets the content of an attribute as a String获取属性的内容作为字符串

setString()

Sets the content of an attribute as a String将属性的内容设置为字符串

getInt()

Gets the content of an attribute as an int获取属性的内容作为 int

setInt()

Sets the content of an attribute as an int将属性的内容设置为 int

getFloat()

Gets the content of an attribute as a float获取属性的内容作为浮点

setFloat()

Sets the content of an attribute as a float将属性的内容设置为浮点型

getContent()

Gets the content of an element获取元素的内容

getIntContent()

Gets the content of an element as an int

获取元素的内容作为 int

getFloatContent()

Gets the content of an element as a float

获取元素的内容作为浮点型

setContent()

Sets the content of an element

设置元素的内容

format()

Formats XML data as a String

xml 数据格式化为字符串

toString()

Gets XML data as a String using default formatting使用默认格式将 xml 数据作为字符串获取

Constructor

XML(name)

Parameters

name

String: creates a node with this name

 

名称字符串: 创建具有此名称的节点

Related

loadXML()
parseXML()
saveXML()



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

留下一个回复

你的email不会被公开。