Class XmlResourceHelper
java.lang.Object
com.pnfsoftware.jeb.core.units.code.android.XmlResourceHelper
- Direct Known Subclasses:
ApkXmlResourceHelper
This helper class facilitates access to the data contained in an XML resource. In particular, the
readAttributeXxx methods allow easy retrieval of attribute values by tag names,
throughout the entire document.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreate a helper around the provided XML unit.Create a helper around the provided low-level XML document object. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringbuildAttributeName(String name) Build an attribute name usable for lookups.convertEltlist(NodeList nodelist) Convert a DOM node list to a Java list of elements.convertNodelist(NodeList nodelist) Convert a DOM node list to a Java list.protected StringRetrieve an attribute value from an element.This low-level method offers access to theorg.w3c.dom.Elementholding the root.protected StringgetSimpleName(String name) Remove a namespace prefix from a name.booleanhasAttributeValue(String tagName, String attrName, String wantedAttrValue) Determine if a tag has a specific attribute value.protected booleanisFullyQualifiedName(String name) Determine if an attribute name includes a namespace prefix.protected booleanisSimpleName(String name) Determine if an attribute name has no namespace prefix.protected voidreadAttribute(String tagName, String attrName) Retrieve the attribute value of the first tag having the provided name.readAttributes(String tagName, String attrName) Retrieve the attribute values for all tags having the provided name.readMultiAttributes(String tagName, String... attrNames) Retrieve several attribute values for all tags having the provided name.
-
Field Details
-
doc
Source XML document. -
rootElt
Root element of the source document.
-
-
Constructor Details
-
XmlResourceHelper
Create a helper around the provided XML unit.- Parameters:
xml- XML unit
-
XmlResourceHelper
Create a helper around the provided low-level XML document object.- Parameters:
doc- XML document
-
-
Method Details
-
prepare
The default implementation retrieves sets thedocandrootEltattributes. Overrides must call this implementation first.- Parameters:
doc- XML document
-
getRootElement
This low-level method offers access to theorg.w3c.dom.Elementholding the root.- Returns:
- the document root element
-
buildAttributeName
Build an attribute name usable for lookups.- Parameters:
name- attribute name- Returns:
- the lookup name
-
convertNodelist
Convert a DOM node list to a Java list.- Parameters:
nodelist- DOM node list- Returns:
- the converted list
-
convertEltlist
Convert a DOM node list to a Java list of elements.- Parameters:
nodelist- DOM node list of elements- Returns:
- the converted list
-
readAttribute
Retrieve the attribute value of the first tag having the provided name.- Parameters:
tagName- tag name, or null for the root manifest elementattrName- attribute name- Returns:
- the value (possibly empty if the attribute is not found in the tag), or null (if no element with the provided tag name was found in the document)
-
readAttributes
Retrieve the attribute values for all tags having the provided name.- Parameters:
tagName- tag name, or null for the root manifest elementattrName- attribute name- Returns:
- a list of non-null strings
-
hasAttributeValue
Determine if a tag has a specific attribute value.- Parameters:
tagName- tag name, or null for the root manifest elementattrName- attribute namewantedAttrValue- expected attribute value- Returns:
- true if the value is present
-
readMultiAttributes
Retrieve several attribute values for all tags having the provided name.- Parameters:
tagName- tag name, or null for the root manifest elementattrNames- a collection of attributes to be retrieved- Returns:
- rows of attribute values, one row per matching element
-
getAttr
Retrieve an attribute value from an element.- Parameters:
elt- elementname- attribute name- Returns:
- the attribute value, or an empty string
-
isFullyQualifiedName
Determine if an attribute name includes a namespace prefix.- Parameters:
name- attribute name- Returns:
- true if the name contains a prefix separator
-
isSimpleName
Determine if an attribute name has no namespace prefix.- Parameters:
name- attribute name- Returns:
- true if the name is simple
-
getSimpleName
Remove a namespace prefix from a name.- Parameters:
name- attribute or element name- Returns:
- the simple name
-