public final class XmlUtil extends Object implements Serializable
| Modifier and Type | Class and Description |
|---|---|
static class |
XmlUtil.CheckStringResult
Result from checking string
|
| Modifier and Type | Field and Description |
|---|---|
static int |
xmlError
Errors occurred during tidy
|
static int |
xmlMissing
Field has no value
|
static int |
xmlNotXml
The parameter was untagged text
|
static int |
xmlOk
Field is tidied
|
static int |
xmlTidyException
Exception when tidied
|
static int |
xmlTidyNull
Xml became null when tidied
|
static int |
xmlUntidy
Xml is (probably) valid but not tidied
|
| Constructor and Description |
|---|
XmlUtil() |
| Modifier and Type | Method and Description |
|---|---|
static void |
checkString(String id,
String val,
XmlUtil.CheckStringResult crs,
boolean emptyOk)
This does everything tidyString does with the addition that it adjusts
the result to indicate something about the original string.
|
static QName |
fromNode(Node nd)
Return a QName for the node
|
static String |
getAttrVal(Element el,
String name)
Return the value of the named attribute of the given element.
|
static String |
getAttrVal(NamedNodeMap nnm,
String name)
Return the attribute value of the named attribute from the given map.
|
static String |
getElementContent(Element el)
Return the content for the current element.
|
static String |
getElementContent(Element el,
boolean trim)
Return the content for the current element.
|
static List<Element> |
getElements(Node nd)
All the children must be elements or white space text nodes.
|
static Element[] |
getElementsArray(Node nd) |
static String |
getOneNodeVal(Node el)
Get the value of an element.
|
static String |
getOneNodeVal(Node el,
String name)
Get the value of an element.
|
static Node |
getOneTaggedNode(Node el,
String name)
Get the single named element.
|
static Element |
getOnlyElement(Node nd) |
static String |
getReqAttrVal(Element el,
String name)
Return the required value of the named attribute of the given element.
|
static String |
getReqOneNodeVal(Node el)
Get the value of an element.
|
static String |
getReqOneNodeVal(Node el,
String name)
Get the value of an element.
|
static Boolean |
getYesNoAttrVal(NamedNodeMap nnm,
String name)
The attribute value of the named attribute in the given map must be
absent or "yes" or "no".
|
static boolean |
hasChildren(Element el)
See if this node has any children
|
static boolean |
hasContent(Element el)
Return true if the current element has non zero length content.
|
static boolean |
isEmpty(Element el)
See if this node is empty
|
static boolean |
nodeMatches(Node nd,
QName tag)
See if node matches tag
|
static int |
numAttrs(Node nd) |
static void |
setElementContent(Node n,
String s)
Replace the content for the current element.
|
static void |
tidyString(String id,
String val,
XmlUtil.CheckStringResult crs)
Given a string return a tidied form of the string.
|
static String |
tidyXML(String id,
String val,
PrintWriter err)
Given a string return a tidied form of the string.
|
public static final int xmlOk
public static final int xmlMissing
public static final int xmlUntidy
public static final int xmlError
public static final int xmlTidyNull
public static final int xmlNotXml
public static final int xmlTidyException
public static void tidyString(String id, String val, XmlUtil.CheckStringResult crs)
Take care, certain forms of input result in no output. Note that we watch specifically for a line consisting of a single new line character.
We also check for a string that is just text with no markup. This check is rather simple.
If the first non-whitespace character is not > we assume simple text input and optionally attempt to tag it.
This check is suppressed if tagUntagged = false.
id - String to identify inputval - String to tidycrs - Object to hold resultspublic static void checkString(String id, String val, XmlUtil.CheckStringResult crs, boolean emptyOk)
if emptyOk is false and the result is null the status is xmlNull otherwise a null value is considered OK.
We also check for the value changing. A change indicates some tidying took place so we return xmlUntidy.
id - String to identify inputval - String to tidycrs - Object to hold resultsemptyOk - True if empty text is not specialpublic static String tidyXML(String id, String val, PrintWriter err) throws Exception
Take care, certain forms of input result in no output. Note that we watch specifically for a line cosisting of a single new line character.
We also check for a string that is just text with no markup. This check is rather simple.
If the first non-whitespace character is not > we assume simple text input and optionally attempt to tag it.
id - String to identify inputval - String to tidyerr - An error output streamException - When tidying fails.public static Node getOneTaggedNode(Node el, String name) throws SAXException
el - Nodename - String tag name of required nodeSAXExceptionpublic static String getOneNodeVal(Node el, String name) throws SAXException
el - Node whose value we wantname - String name to make exception messages more readableSAXExceptionpublic static String getOneNodeVal(Node el) throws SAXException
el - Node whose value we wantSAXExceptionpublic static String getReqOneNodeVal(Node el, String name) throws SAXException
el - Node whose value we wantname - String name to make exception messages more readableSAXExceptionpublic static String getReqOneNodeVal(Node el) throws SAXException
el - Node whose value we wantSAXExceptionpublic static String getAttrVal(Element el, String name) throws SAXException
el - Elementname - String name of desired attributeSAXExceptionpublic static String getReqAttrVal(Element el, String name) throws SAXException
el - Elementname - String name of desired attributeSAXExceptionpublic static String getAttrVal(NamedNodeMap nnm, String name)
nnm - NamedNodeMapname - String name of desired attributepublic static Boolean getYesNoAttrVal(NamedNodeMap nnm, String name) throws SAXException
nnm - NamedNodeMapname - String name of desired attributeSAXExceptionpublic static int numAttrs(Node nd)
nd - public static List<Element> getElements(Node nd) throws SAXException
nd - SAXExceptionpublic static String getElementContent(Element el, boolean trim) throws SAXException
This is only intended for an element with no child elements.
el - trim - true to trim surrounding white-spaceSAXExceptionpublic static void setElementContent(Node n, String s) throws SAXException
n - elements - string contentSAXExceptionpublic static String getElementContent(Element el) throws SAXException
This is only intended for an element with no child elements.
el - SAXExceptionpublic static boolean hasContent(Element el) throws SAXException
el - SAXExceptionpublic static boolean hasChildren(Element el) throws SAXException
el - SAXExceptionpublic static boolean isEmpty(Element el) throws SAXException
el - SAXExceptionpublic static Element[] getElementsArray(Node nd) throws SAXException
nd - SAXExceptionpublic static boolean nodeMatches(Node nd, QName tag)
nd - tag - public static QName fromNode(Node nd)
nd - public static Element getOnlyElement(Node nd) throws SAXException
nd - SAXException - if not exactly one child elemntCopyright © 2016 Bedework. All rights reserved.