MCPcopy Index your code
hub / github.com/processing/p5.js / xml

Function xml

src/io/p5.XML.js:1145–1197  ·  view source on GitHub ↗
(p5, fn)

Source from the content-addressed store, hash-verified

1143}
1144
1145function xml(p5, fn){
1146 /**
1147 * A class to describe an XML object.
1148 *
1149 * Each `p5.XML` object provides an easy way to interact with XML data.
1150 * Extensible Markup Language
1151 * (<a href="https://developer.mozilla.org/en-US/docs/Web/XML/XML_introduction" target="_blank">XML</a>)
1152 * is a standard format for sending data between applications. Like HTML, the
1153 * XML format is based on tags and attributes, as in
1154 * `<time units="s">1234</time>`.
1155 *
1156 * Note: Use <a href="#/p5/loadXML">loadXML()</a> to load external XML files.
1157 *
1158 * @class p5.XML
1159 * @example
1160 * let myXML;
1161 *
1162 * async function setup() {
1163 * // Load the XML and create a p5.XML object.
1164 * myXML = await loadXML('assets/animals.xml');
1165 *
1166 * createCanvas(100, 100);
1167 *
1168 * background(200);
1169 *
1170 * // Get an array with all mammal tags.
1171 * let mammals = myXML.getChildren('mammal');
1172 *
1173 * // Style the text.
1174 * textAlign(LEFT, CENTER);
1175 * textFont('Courier New');
1176 * textSize(14);
1177 *
1178 * // Iterate over the mammals array.
1179 * for (let i = 0; i < mammals.length; i += 1) {
1180 *
1181 * // Calculate the y-coordinate.
1182 * let y = (i + 1) * 25;
1183 *
1184 * // Get the mammal's common name.
1185 * let name = mammals[i].getContent();
1186 *
1187 * // Display the mammal's name.
1188 * text(name, 20, y);
1189 * }
1190 *
1191 * describe(
1192 * 'The words "Goat", "Leopard", and "Zebra" written on three separate lines. The text is black on a gray background.'
1193 * );
1194 * }
1195 */
1196 p5.XML = XML;
1197}
1198
1199export default xml;
1200export { XML };

Callers 2

loadXML.jsFile · 0.85
p5.XML.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected