303 lines
11 KiB
HTML
303 lines
11 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
<head>
|
|
<title>XML \ Language (API) \ Processing 2+</title>
|
|
|
|
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="Author" content="Processing Foundation" />
|
|
<meta name="Publisher" content="Processing Foundation" />
|
|
<meta name="Keywords" content="Processing, Sketchbook, Programming, Coding, Code, Art, Design" />
|
|
<meta name="Description" content="Processing is a flexible software sketchbook and a language for learning how to code within the context of the visual arts. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology." />
|
|
<meta name="Copyright" content="All contents copyright the Processing Foundation, Ben Fry, Casey Reas, and the MIT Media Laboratory" />
|
|
|
|
<script src="javascript/modernizr-2.6.2.touch.js" type="text/javascript"></script>
|
|
<link href="css/style.css" rel="stylesheet" type="text/css" />
|
|
|
|
</head>
|
|
<body id="Langauge-en" onload="" >
|
|
|
|
<!-- ==================================== PAGE ============================ -->
|
|
<div id="container">
|
|
|
|
|
|
<!-- ==================================== HEADER ============================ -->
|
|
<div id="ribbon">
|
|
<ul class="left">
|
|
<li class="highlight"><a href="http://processing.org/">Processing</a></li>
|
|
<li><a href="http://p5js.org/">p5.js</a></li>
|
|
<li><a href="http://py.processing.org/">Processing.py</a></li>
|
|
<li><a href="http://android.processing.org/">Processing for Android</a></li>
|
|
</ul>
|
|
<ul class="right">
|
|
<li><a href="https://processingfoundation.org/">Processing Foundation</a></li>
|
|
</ul>
|
|
<div class="clear"></div>
|
|
</div>
|
|
<div id="header">
|
|
<a href="/" title="Back to the Processing cover."><div class="processing-logo no-cover" alt="Processing cover"></div></a>
|
|
<form name="search" method="get" action="//www.google.com/search">
|
|
<p><input type="hidden" name="as_sitesearch" value="processing.org" />
|
|
<input type="text" name="as_q" value="" size="20" class="text" />
|
|
<input type="submit" value=" " /></p>
|
|
</form>
|
|
</div>
|
|
<a id="TOP" name="TOP"></a>
|
|
|
|
<div id="navigation">
|
|
<div class="navBar" id="mainnav">
|
|
<a href="index.html" class='active'>Language</a><br>
|
|
<a href="libraries/index.html" >Libraries</a><br>
|
|
<a href="tools/index.html">Tools</a><br>
|
|
<a href="environment/index.html">Environment</a><br>
|
|
</div>
|
|
|
|
<script> document.querySelectorAll(".processing-logo")[0].className = "processing-logo"; </script>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- ==================================== CONTENT - Headers ============================ -->
|
|
<div class="content">
|
|
|
|
<p class="ref-notice">This reference is for Processing 3.0+. If you have a previous version, use the reference included with your software in the Help menu. If you see any errors or have suggestions, <a href="https://github.com/processing/processing-docs/issues?state=open">please let us know</a>. If you prefer a more technical reference, visit the <a href="http://processing.github.io/processing-javadocs/core/">Processing Core Javadoc</a> and <a href="http://processing.github.io/processing-javadocs/libraries/">Libraries Javadoc</a>.</p>
|
|
|
|
<table cellpadding="0" cellspacing="0" border="0" class="ref-item">
|
|
<tr class="name-row">
|
|
<th scope="row">Name</th>
|
|
<td><h3>XML</h3></td>
|
|
</tr>
|
|
|
|
<tr class=""><th scope="row">Examples</th><td><div class="example"><pre >
|
|
// 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
|
|
</pre></div>
|
|
</td></tr>
|
|
|
|
<tr class="">
|
|
<th scope="row">Description</th>
|
|
<td>
|
|
<b>XML</b> is a representation of an XML object, able to parse XML code. Use <b>loadXML()</b> to load external XML files and create <b>XML</b> objects.<br />
|
|
<br />
|
|
Only files encoded as UTF-8 (or plain ASCII) are parsed properly; the encoding parameter inside XML files is ignored.
|
|
</td>
|
|
</tr>
|
|
|
|
|
|
|
|
<tr class=""><th scope="row">Methods</th><td><table cellpadding="0" cellspacing="0" border="0"><tr class="">
|
|
|
|
<th scope="row"><a href="XML_getParent_.html">getParent()</a></th>
|
|
<td>Gets a copy of the element's parent</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_getName_.html">getName()</a></th>
|
|
<td>Gets the element's full name</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_setName_.html">setName()</a></th>
|
|
<td>Sets the element's name</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_hasChildren_.html">hasChildren()</a></th>
|
|
<td>Checks whether or not an element has any children</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_listChildren_.html">listChildren()</a></th>
|
|
<td>Returns the names of all children as an array</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_getChildren_.html">getChildren()</a></th>
|
|
<td>Returns an array containing all child elements</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_getChild_.html">getChild()</a></th>
|
|
<td>Returns the child element with the specified index value or path</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_addChild_.html">addChild()</a></th>
|
|
<td>Appends a new child to the element</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_removeChild_.html">removeChild()</a></th>
|
|
<td>Removes the specified child</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_getAttributeCount_.html">getAttributeCount()</a></th>
|
|
<td>Counts the specified element's number of attributes</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_listAttributes_.html">listAttributes()</a></th>
|
|
<td>Returns a list of names of all attributes as an array</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_hasAttribute_.html">hasAttribute()</a></th>
|
|
<td>Checks whether or not an element has the specified attribute</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_getString_.html">getString()</a></th>
|
|
<td>Gets the content of an attribute as a String</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_setString_.html">setString()</a></th>
|
|
<td>Sets the content of an attribute as a String</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_getInt_.html">getInt()</a></th>
|
|
<td>Gets the content of an attribute as an int</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_setInt_.html">setInt()</a></th>
|
|
<td>Sets the content of an attribute as an int</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_getFloat_.html">getFloat()</a></th>
|
|
<td>Gets the content of an attribute as a float</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_setFloat_.html">setFloat()</a></th>
|
|
<td>Sets the content of an attribute as a float</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_getContent_.html">getContent()</a></th>
|
|
<td>Gets the content of an element</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_getIntContent_.html">getIntContent()</a></th>
|
|
<td>Gets the content of an element as an int</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_getFloatContent_.html">getFloatContent()</a></th>
|
|
<td>Gets the content of an element as a float</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_setContent_.html">setContent()</a></th>
|
|
<td>Sets the content of an element</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_format_.html">format()</a></th>
|
|
<td>Formats XML data as a String</td>
|
|
</tr>
|
|
<tr class="">
|
|
|
|
<th scope="row"><a href="XML_toString_.html">toString()</a></th>
|
|
<td>Gets XML data as a String using default formatting</td>
|
|
</tr></table></td></tr>
|
|
|
|
<tr class=""><th scope="row">Constructor</th><td><pre>XML(<kbd>name</kbd>)
|
|
</pre></td></tr>
|
|
<tr class=""> <th scope="row">Parameters</th><td><table cellpadding="0" cellspacing="0" border="0"><tr class="">
|
|
<th scope="row" class="code">name</th>
|
|
<td>String: creates a node with this name</td>
|
|
</tr></table></td> </tr>
|
|
<tr class=""><th scope="row">Related</th><td><a class="code" href="loadXML_.html">loadXML()</a><br />
|
|
<a class="code" href="parseXML_.html">parseXML()</a><br />
|
|
<a class="code" href="saveXML_.html">saveXML()</a><br /></td></tr>
|
|
</table>
|
|
|
|
Updated on April 30, 2017 02:33:20pm EDT<br /><br />
|
|
|
|
<!-- Creative Commons License -->
|
|
|
|
<div class="license">
|
|
<a rel="license" href="//creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border: none" src="https://licensebuttons.net/l/by-nc-sa/4.0/88x31.png" /></a>
|
|
</div>
|
|
<!--
|
|
|
|
<?xpacket begin='' id=''?>
|
|
<x:xmpmeta xmlns:x='adobe:ns:meta/'>
|
|
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
|
|
<rdf:Description rdf:about=''
|
|
xmlns:xapRights='http://ns.adobe.com/xap/1.0/rights/'>
|
|
<xapRights:Marked>True</xapRights:Marked>
|
|
</rdf:Description>
|
|
<rdf:Description rdf:about=''
|
|
xmlns:xapRights='http://ns.adobe.com/xap/1.0/rights/'
|
|
>
|
|
<xapRights:UsageTerms>
|
|
<rdf:Alt>
|
|
<rdf:li xml:lang='x-default' >This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.</rdf:li>
|
|
<rdf:li xml:lang='en' >This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.</rdf:li>
|
|
</rdf:Alt>
|
|
</xapRights:UsageTerms>
|
|
</rdf:Description>
|
|
<rdf:Description rdf:about=''
|
|
xmlns:cc='http://creativecommons.org/ns#'>
|
|
<cc:license rdf:resource='http://creativecommons.org/licenses/by-nc-sa/4.0/'/>
|
|
</rdf:Description>
|
|
|
|
</rdf:RDF>
|
|
</x:xmpmeta>
|
|
<?xpacket end='r'?>
|
|
|
|
-->
|
|
|
|
</div>
|
|
|
|
<!-- ==================================== FOOTER ============================ -->
|
|
<div id="footer">
|
|
<div id="copyright">Processing is an open project intiated by <a href="http://benfry.com/">Ben Fry</a> and <a href="http://reas.com">Casey Reas</a>. It is developed by a <a href="about/people.html">team of volunteers</a>. </div>
|
|
<div id="colophon">
|
|
|
|
<a href="copyright.html">© Info</a>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
<script src="javascript/jquery-1.9.1.min.js"></script>
|
|
<script src="javascript/site.js" type="text/javascript"></script>
|
|
</body>
|
|
|
|
</html>
|