Class XmlUtil
java.lang.Object
com.pnfsoftware.jeb.util.encoding.xml.XmlUtil
XML utility methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanCompare a substring with an expected literal.static booleanCompare a substring with an expected literal, ignoring case.static DocumentBuilderFactorycreateSecureDocumentBuilderFactory(boolean disallowDoctypeDecl) Create a safeDocumentBuilderFactoryobject.static StringFormat a document as text.getChildrenElements(Element e, String childName) Find all direct child elements with the requested name.static ElementgetFirstChildElement(Element e, String childName) Find the first direct child element with the requested name.static booleanisSpace(int codePoint) Determine whether the provided code point is a white space character.static intreadToken(String str, int idx, Collection<Integer> stoppers, String[] atoken) Read a token.static intreadToken(String str, int idx, Collection<Integer> stoppers, String[] atoken, boolean mustBeQuoted, boolean handleBackslashAxmlStyle) Read a token.static intskipSomeSpaces(String str, int idx) Skip 1+ WSP characters.static intskipSpaces(String str, int idx) Skip 0+ WSP characters.static intSkip WSP characters.
-
Method Details
-
createSecureDocumentBuilderFactory
public static DocumentBuilderFactory createSecureDocumentBuilderFactory(boolean disallowDoctypeDecl) throws ParserConfigurationException Create a safeDocumentBuilderFactoryobject.- Parameters:
disallowDoctypeDecl-- Returns:
- the factory object
- Throws:
ParserConfigurationException
-
isSpace
public static boolean isSpace(int codePoint) Determine whether the provided code point is a white space character.- Parameters:
codePoint- Unicode code point- Returns:
- true if the code point is XML whitespace or a Java space character
-
skipSomeSpaces
Skip 1+ WSP characters.- Parameters:
str- input stringidx- start index- Returns:
- new index after skipped whitespace
-
skipSpaces
Skip 0+ WSP characters.- Parameters:
str- input stringidx- start index- Returns:
- new index after skipped whitespace
-
skipWSP
Skip WSP characters.- Parameters:
str- stringidx- start indexminSpaceCount- the method will raise if fewer WSP chars were skipped- Returns:
- new index, after skipping WSP chars
-
readToken
Read a token.- Parameters:
str- input stringidx- token start (cannot be a wsp); may be a single-quote or double-quotestoppers- optional code points that terminate an unquoted tokenatoken- output token- Returns:
- index immediately after the token
-
readToken
public static int readToken(String str, int idx, Collection<Integer> stoppers, String[] atoken, boolean mustBeQuoted, boolean handleBackslashAxmlStyle) Read a token.- Parameters:
str- input stringidx- token start (cannot be a wsp); may be a single-quote or double-quotestoppers- optional code points that terminate an unquoted tokenatoken- output tokenmustBeQuoted- true if the token must start with a quotehandleBackslashAxmlStyle- true to decode Android resource backslash escapes- Returns:
- index immediately after the token
-
compare
Compare a substring with an expected literal.- Parameters:
str- input stringidx- substring start indexexpected- expected literal- Returns:
- true if
expectedstarts atidx
-
compareCI
Compare a substring with an expected literal, ignoring case.- Parameters:
str- input stringidx- substring start indexexpected- expected literal- Returns:
- true if
expectedstarts atidx, ignoring case
-
getFirstChildElement
Find the first direct child element with the requested name.- Parameters:
e- parent elementchildName- child tag name- Returns:
- first matching child element, or null
-
getChildrenElements
Find all direct child elements with the requested name.- Parameters:
e- parent elementchildName- child tag name- Returns:
- list of matching child elements
-
format
Format a document as text.- Parameters:
doc- input document- Returns:
- textual representation of the document
-