當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Processing XML.getChild()用法及代碼示例

Processing, 類XML中的getChild()用法介紹。

用法

  • .getChild(index)
  • .getChild(name)

參數

  • name (String) 元素名稱或路徑/到/元素

返回

  • XML

說明

返回與name 參數匹配的元素的第一個子元素。名稱或路徑是一係列元素和子元素,以斜線分隔。

例子

PShape states;
PShape ohio;

void setup() {
  size(100, 100);
  states = loadShape("tristate.svg");
  ohio = states.getChild("OH");
  ohio.disableStyle();
}

void draw() {
  background(0);
  shape(states, -48, 5);
  fill(102, 0, 0);
  shape(ohio, -48, 5);
}
// 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 firstChild = xml.getChild("animal");
  println(firstChild.getContent());
}

// Sketch prints:
// Goat

相關用法


注:本文由純淨天空篩選整理自processing.org大神的英文原創作品 XML.getChild()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。