3939 * This is the base class used for the Processing XML library,
4040 * representing a single node of an XML tree.
4141 */
42- public class PNode implements Serializable {
42+ public class XML implements Serializable {
4343
4444 /** The internal representation, a DOM node. */
4545 protected Node node ;
@@ -48,21 +48,21 @@ public class PNode implements Serializable {
4848 protected String name ;
4949
5050 /** The parent element. */
51- protected PNode parent ;
51+ protected XML parent ;
5252
5353 /** Child elements, once loaded. */
54- protected PNode [] children ;
54+ protected XML [] children ;
5555
5656
57- protected PNode () { }
57+ protected XML () { }
5858
5959
6060 /**
6161 * Begin parsing XML data passed in from a PApplet. This code
6262 * wraps exception handling, for more advanced exception handling,
6363 * use the constructor that takes a Reader or InputStream.
6464 */
65- public PNode (PApplet parent , String filename ) {
65+ public XML (PApplet parent , String filename ) {
6666 this (parent .createReader (filename ));
6767 }
6868
@@ -72,7 +72,7 @@ public PNode(PApplet parent, String filename) {
7272// }
7373
7474
75- public PNode (Reader reader ) {
75+ public XML (Reader reader ) {
7676 try {
7777 DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
7878// factory.setValidating(false);
@@ -123,7 +123,7 @@ public PNode(Reader reader) {
123123
124124 // TODO is there a more efficient way of doing this? wow.
125125 // i.e. can we use one static document object for all PNodeXML objects?
126- public PNode (String name ) {
126+ public XML (String name ) {
127127 try {
128128 DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
129129 DocumentBuilder builder = factory .newDocumentBuilder ();
@@ -147,7 +147,7 @@ public PNode(String name) {
147147// }
148148
149149
150- protected PNode ( PNode parent , Node node ) {
150+ protected XML ( XML parent , Node node ) {
151151 this .node = node ;
152152 this .parent = parent ;
153153
@@ -157,16 +157,16 @@ protected PNode(PNode parent, Node node) {
157157 }
158158
159159
160- static public PNode parse (String xml ) {
161- return new PNode (new StringReader (xml ));
160+ static public XML parse (String xml ) {
161+ return new XML (new StringReader (xml ));
162162 }
163163
164164
165165 /**
166166 * Returns the parent element. This method returns null for the root
167167 * element.
168168 */
169- public PNode getParent () {
169+ public XML getParent () {
170170 return this .parent ;
171171 }
172172
@@ -197,9 +197,9 @@ protected void checkChildren() {
197197 if (children == null ) {
198198 NodeList kids = node .getChildNodes ();
199199 int childCount = kids .getLength ();
200- children = new PNode [childCount ];
200+ children = new XML [childCount ];
201201 for (int i = 0 ; i < childCount ; i ++) {
202- children [i ] = new PNode (this , kids .item (i ));
202+ children [i ] = new XML (this , kids .item (i ));
203203 }
204204 }
205205 }
@@ -241,7 +241,7 @@ public String[] listChildren() {
241241 /**
242242 * Returns an array containing all the child elements.
243243 */
244- public PNode [] getChildren () {
244+ public XML [] getChildren () {
245245// NodeList children = node.getChildNodes();
246246// int childCount = children.getLength();
247247// XMLElement[] kids = new XMLElement[childCount];
@@ -259,7 +259,7 @@ public PNode[] getChildren() {
259259 * Quick accessor for an element at a particular index.
260260 * @author processing.org
261261 */
262- public PNode getChild (int index ) {
262+ public XML getChild (int index ) {
263263 checkChildren ();
264264 return children [index ];
265265 }
@@ -270,13 +270,13 @@ public PNode getChild(int index) {
270270 * @param name element name or path/to/element
271271 * @return the first matching element
272272 */
273- public PNode getChild (String name ) {
273+ public XML getChild (String name ) {
274274 if (name .indexOf ('/' ) != -1 ) {
275275 return getChildRecursive (PApplet .split (name , '/' ), 0 );
276276 }
277277 int childCount = getChildCount ();
278278 for (int i = 0 ; i < childCount ; i ++) {
279- PNode kid = getChild (i );
279+ XML kid = getChild (i );
280280 String kidName = kid .getName ();
281281 if (kidName != null && kidName .equals (name )) {
282282 return kid ;
@@ -293,10 +293,10 @@ public PNode getChild(String name) {
293293 * @return matching element or null if no match
294294 * @author processing.org
295295 */
296- protected PNode getChildRecursive (String [] items , int offset ) {
296+ protected XML getChildRecursive (String [] items , int offset ) {
297297 // if it's a number, do an index instead
298298 if (Character .isDigit (items [offset ].charAt (0 ))) {
299- PNode kid = getChild (Integer .parseInt (items [offset ]));
299+ XML kid = getChild (Integer .parseInt (items [offset ]));
300300 if (offset == items .length -1 ) {
301301 return kid ;
302302 } else {
@@ -305,7 +305,7 @@ protected PNode getChildRecursive(String[] items, int offset) {
305305 }
306306 int childCount = getChildCount ();
307307 for (int i = 0 ; i < childCount ; i ++) {
308- PNode kid = getChild (i );
308+ XML kid = getChild (i );
309309 String kidName = kid .getName ();
310310 if (kidName != null && kidName .equals (items [offset ])) {
311311 if (offset == items .length -1 ) {
@@ -326,56 +326,56 @@ protected PNode getChildRecursive(String[] items, int offset) {
326326 * @return array of child elements that match
327327 * @author processing.org
328328 */
329- public PNode [] getChildren (String name ) {
329+ public XML [] getChildren (String name ) {
330330 if (name .indexOf ('/' ) != -1 ) {
331331 return getChildrenRecursive (PApplet .split (name , '/' ), 0 );
332332 }
333333 // if it's a number, do an index instead
334334 // (returns a single element array, since this will be a single match
335335 if (Character .isDigit (name .charAt (0 ))) {
336- return new PNode [] { getChild (Integer .parseInt (name )) };
336+ return new XML [] { getChild (Integer .parseInt (name )) };
337337 }
338338 int childCount = getChildCount ();
339- PNode [] matches = new PNode [childCount ];
339+ XML [] matches = new XML [childCount ];
340340 int matchCount = 0 ;
341341 for (int i = 0 ; i < childCount ; i ++) {
342- PNode kid = getChild (i );
342+ XML kid = getChild (i );
343343 String kidName = kid .getName ();
344344 if (kidName != null && kidName .equals (name )) {
345345 matches [matchCount ++] = kid ;
346346 }
347347 }
348- return (PNode []) PApplet .subset (matches , 0 , matchCount );
348+ return (XML []) PApplet .subset (matches , 0 , matchCount );
349349 }
350350
351351
352- protected PNode [] getChildrenRecursive (String [] items , int offset ) {
352+ protected XML [] getChildrenRecursive (String [] items , int offset ) {
353353 if (offset == items .length -1 ) {
354354 return getChildren (items [offset ]);
355355 }
356- PNode [] matches = (PNode []) getChildren (items [offset ]);
357- PNode [] outgoing = new PNode [0 ];
356+ XML [] matches = (XML []) getChildren (items [offset ]);
357+ XML [] outgoing = new XML [0 ];
358358 for (int i = 0 ; i < matches .length ; i ++) {
359- PNode [] kidMatches = matches [i ].getChildrenRecursive (items , offset +1 );
360- outgoing = (PNode []) PApplet .concat (outgoing , kidMatches );
359+ XML [] kidMatches = matches [i ].getChildrenRecursive (items , offset +1 );
360+ outgoing = (XML []) PApplet .concat (outgoing , kidMatches );
361361 }
362362 return outgoing ;
363363 }
364364
365365
366- public PNode addChild (String tag ) {
366+ public XML addChild (String tag ) {
367367 Document document = node .getOwnerDocument ();
368368 Node newChild = document .createElement (tag );
369369 node .appendChild (newChild );
370- PNode pn = new PNode (this , newChild );
370+ XML pn = new XML (this , newChild );
371371 if (children != null ) {
372- children = (PNode []) PApplet .concat (children , new PNode [] { pn });
372+ children = (XML []) PApplet .concat (children , new XML [] { pn });
373373 }
374374 return pn ;
375375 }
376376
377377
378- public void removeChild (PNode kid ) {
378+ public void removeChild (XML kid ) {
379379 node .removeChild (kid .node );
380380 children = null ; // TODO not efficient
381381 }
0 commit comments