add trim() method to XML (removes #text nodes)

This commit is contained in:
Ben Fry
2014-08-12 10:15:05 -04:00
parent 02a20022ee
commit 7d11ece606
3 changed files with 65 additions and 8 deletions

View File

@@ -33,6 +33,9 @@ import org.xml.sax.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;
import processing.core.PApplet;
@@ -582,6 +585,25 @@ public class XML implements Serializable {
}
public void trim() {
try {
XPathFactory xpathFactory = XPathFactory.newInstance();
XPathExpression xpathExp =
xpathFactory.newXPath().compile("//text()[normalize-space(.) = '']");
NodeList emptyTextNodes = (NodeList)
xpathExp.evaluate(node, XPathConstants.NODESET);
// Remove each empty text node from document.
for (int i = 0; i < emptyTextNodes.getLength(); i++) {
Node emptyTextNode = emptyTextNodes.item(i);
emptyTextNode.getParentNode().removeChild(emptyTextNode);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
// /** Remove whitespace nodes. */
// public void trim() {
////// public static boolean isWhitespace(XML xml) {

View File

@@ -1,6 +1,13 @@
0230 core (3.0a3)
X add another NaN check when sorting FloatList/Dict classes
X if all values were NaN, an ArrayIndexOutOfBoundsException was thrown
X PShape for JAVA2D
X https://github.com/processing/processing/pull/2756
X add trim() method to the XML library
andres
X maximizing window leads to erroneous mouse coordinates
X https://github.com/processing/processing/issues/2562
earlier
X PShape disableStyle() does not work with createShape()
@@ -16,7 +23,8 @@ X Drawing RECT PShape with rounded corners crashes the sketch
X https://github.com/processing/processing/issues/2648
X Corrected a typo in Tessellator#addQuadraticVertex()
X https://github.com/processing/processing/pull/2649
X fix tiny typo in Table writeHTML()
X https://github.com/processing/processing/pull/2773
applet/component
_ remove Applet as base class
@@ -32,6 +40,7 @@ _ make sure it works with retina/canvas/strategy as well
processing.data
_ lots of 'data' changes down below
_ need a better method for "missing" data in Table
_ if missing int is zero, can't just remove those values from saving a table
_ but for NaN values, it's a necessity
@@ -86,6 +95,8 @@ _ draw(s) doesn't work on the returned PShape
hidpi
_ Text is half size in PGraphicsRetina2D
_ https://github.com/processing/processing/issues/2738
_ text not getting the correct font in Retina2D
_ https://github.com/processing/processing/issues/2617
_ saveFrame() with retina render is making black images
_ zero alpha values still a problem with retina renderer
_ https://github.com/processing/processing/issues/2030
@@ -100,7 +111,6 @@ _ no high-dpi support for core on Windows
_ https://github.com/processing/processing/issues/2411
_ retina sketches slow to start
_ https://github.com/processing/processing/issues/2357
_ glw? lwjgl? retina jogl?
_ Text looks blurry in GL Retina
_ https://github.com/processing/processing/issues/2739

View File

@@ -16,7 +16,7 @@ X fixes for mode/tool installation
X https://github.com/processing/processing/pull/2705
X fix mode updating to work properly
X https://github.com/processing/processing/issues/2579
X temp folders not always deleting
X contrib manager temp folders not always deleting
X https://github.com/processing/processing/issues/2606
X problem when removing a mode
X https://github.com/processing/processing/issues/2507
@@ -24,6 +24,12 @@ X autocompletion dialog box sticking
X https://github.com/processing/processing/issues/2741
X Line warning indicators next to scrollbar break after moving around text
X https://github.com/processing/processing/issues/2655
X Code completion generates wrong code
X https://github.com/processing/processing/issues/2753
X Code completion: Hide overloaded methods unless inside parentheses
X https://github.com/processing/processing/issues/2755
X Close auto-completion suggestion box when deleting/backspacing code
X https://github.com/processing/processing/issues/2757
_ remove dependency on oscp5 library for tweak mode
_ https://github.com/processing/processing/issues/2730
@@ -57,6 +63,28 @@ X https://github.com/processing/processing/issues/2654
X https://github.com/processing/processing/pull/2674
X Style completion panel when using Nimbus LAF
X https://github.com/processing/processing/pull/2718
X enums not supported properly
X https://github.com/processing/processing/issues/1390
X http://code.google.com/p/processing/issues/detail?id=1352
X https://github.com/processing/processing/pull/2774
X combining char/int/etc casts in one statement causes preproc trouble
X https://github.com/processing/processing/issues/1936
X https://github.com/processing/processing/pull/2772
X Update contributions.* strings to contrib
X https://github.com/processing/processing/pull/2770
X Style completion panel on windows
X https://github.com/processing/processing/pull/2762
X Update Spanish language strings
X https://github.com/processing/processing/pull/2769
X make --output optional in the command line version
X https://github.com/processing/processing/pull/1866
X https://github.com/processing/processing/issues/1855
X https://github.com/processing/processing/issues/1816
X Fix unneeded scroll bar display in code completion suggestion box
X https://github.com/processing/processing/pull/2763
_ PDE erroneously detects changes in non-sketch files
_ https://github.com/processing/processing/issues/2759
languages
X Japanese https://github.com/processing/processing/pull/2688
@@ -388,13 +416,8 @@ _ it's never useful. students can use { } if they want an empty block
_ missing brackets, unmatched brackets
_ examples added to the bug report
_ http://code.google.com/p/processing/issues/detail?id=6
_ enums not supported properly
_ https://github.com/processing/processing/issues/1390
X http://code.google.com/p/processing/issues/detail?id=1352
low (features)
_ combining char/int/etc casts in one statement causes preproc trouble
_ https://github.com/processing/processing/issues/1936
_ copy running code from /tmp/buildXXxxx on crash of p5
_ should probably make a way to save/recover code
_ make the buildXxxx folders relate to time/date?
@@ -429,6 +452,8 @@ _ http://code.google.com/p/processing/issues/detail?id=8
PDE / Editor
_ clean up /tmp folders used during build
_ https://github.com/processing/processing/issues/1896
_ 'recent' menu doesn't respect examples folder of other p5 versions
_ could write that into the file, that it's an example
_ or write the path as shown in the PDE to the file as simpler