|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.xbus.base.xml.XMLHelper
public class XMLHelper
XMLHelper
offers some support for treating XML structures.
Constructor Summary | |
---|---|
XMLHelper()
|
Method Summary | |
---|---|
static void |
deleteTag(org.w3c.dom.Document doc,
java.lang.String tag)
Deletes the first occurance of the tag in the given
org.w3c.dom.Document . |
static java.lang.String |
getAttribute(org.w3c.dom.Node node,
java.lang.String attr)
Returns the value of the attribute. |
static javax.xml.parsers.DocumentBuilder |
getDocumentBuilder(java.lang.String messageName,
java.lang.String system)
Returns a DocumentBuilder needed for parsing. |
static java.lang.String |
getNodeText(org.w3c.dom.Node tag)
|
static java.lang.String |
getTagAttribute(org.w3c.dom.Document doc,
java.lang.String tag,
java.lang.String attr)
getTagAttribute gets the text of the attribute named
attr in the first occurence of the tag in
the given org.w3c.dom.Document . |
static java.lang.String |
getTagCDATA(org.w3c.dom.Document doc,
java.lang.String tag)
getTagCDATA gets the content of the first CDATA section in
the first occurence of the tag in the given
org.w3c.dom.Document . |
static java.lang.String |
getTagText(org.w3c.dom.Document doc,
java.lang.String tag)
Gets the text of the first occurence of the tag in the
given org.w3c.dom.Document . |
static java.util.Hashtable |
getTagTextList(org.w3c.dom.Document doc,
java.lang.String tag)
Gets the name/value list composed by the child element nodes of the first occurence of the tag in the given
org.w3c.dom.Document . |
static org.w3c.dom.Document |
parseXML(java.lang.String xml,
java.lang.String messageName,
java.lang.String system)
Parses the given XML string. |
static java.lang.String |
serializeXML(org.w3c.dom.Document doc,
java.lang.String systemID)
Serializes a XML document. |
static void |
setTagCDATA(org.w3c.dom.Document doc,
java.lang.String tag,
java.lang.String text)
setTagCDATA sets the text in the first
occurence of the tag in the given
org.w3c.dom.Document as CDATA section. |
static void |
setTagText(org.w3c.dom.Document doc,
java.lang.String tag,
java.lang.String text)
setTagText sets the text in the first
occurence of the tag in the given
org.w3c.dom.Document . |
static void |
setTagTextList(org.w3c.dom.Document doc,
java.lang.String tag,
java.util.Hashtable entries)
setTagTextList stotes a list of name/value pairs in the
first occurence of the tag in the given
org.w3c.dom.Document . |
static void |
setTransformerProperties()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public XMLHelper()
Method Detail |
---|
public static java.lang.String getTagAttribute(org.w3c.dom.Document doc, java.lang.String tag, java.lang.String attr)
getTagAttribute
gets the text of the attribute named
attr
in the first occurence of the tag
in
the given org.w3c.dom.Document
.
doc
- the document in which to searchtag
- the tag to serch forattr
- the attribute name to search for
null
if the no
tag
node exists or if the first tag
node does not contain the attribute attr
.public static java.lang.String getAttribute(org.w3c.dom.Node node, java.lang.String attr)
node
- the node which shall contain the attributeattr
- the attribute name to search for
null
if the node does not
contain the attribute attr
.public static java.lang.String getTagCDATA(org.w3c.dom.Document doc, java.lang.String tag)
getTagCDATA
gets the content of the first CDATA section in
the first occurence of the tag
in the given
org.w3c.dom.Document
.
doc
- the document in which to searchtag
- the tag to serch for
null
if the no
tag
node exists or if the first tag
node does not contain a CDATA section labelled with
tag
exists.public static java.lang.String getTagText(org.w3c.dom.Document doc, java.lang.String tag)
tag
in the
given org.w3c.dom.Document
. Exactly spoken, it retrieves
the value of the first text node of that occurence.
doc
- the document in which to searchtag
- the tag to serch for
null
if no tag
node exists of if the first one does nor contain text.public static java.lang.String getNodeText(org.w3c.dom.Node tag)
public static java.util.Hashtable getTagTextList(org.w3c.dom.Document doc, java.lang.String tag) throws XException
tag
in the given
org.w3c.dom.Document
. The mentioned name is the tag of
the child node and the value in the name/value pair just the node value.
Child nodes other than element nodes are ignored. The value is extracted
from the first child node of the element node - if this one is a text
node. All other child nodes are ignored.
doc
- the document in which to searchtag
- the tag to serch for
null
if no tag
node exists of if the first one does nor contain text.
XException
- if one of the examined element nodes for a name/value pair
has no child or another node than a text node as first childpublic static void setTagTextList(org.w3c.dom.Document doc, java.lang.String tag, java.util.Hashtable entries)
setTagTextList
stotes a list of name/value pairs in the
first occurence of the tag
in the given
org.w3c.dom.Document
. Each pair makes up an element node
with the given name as tag and the given value as node value (in a text
node). If the tag
doesn't exist, nothing happens. If
tag
exists, its previous content is replaced by the list
of text nodes.
doc
- the org.w3c.dom.Document
containing the tagtag
- name of the tag that should be replacedentries
- contains the data for the list of text nodes. Both keys and
elements must be of type String
. The keys are
treated as tag names, the elements are treated as values for
the text nodes.public static void setTagText(org.w3c.dom.Document doc, java.lang.String tag, java.lang.String text)
setTagText
sets the text
in the first
occurence of the tag
in the given
org.w3c.dom.Document
. If the tag
doesn't
exist, nothing happens, otherwise the corresponding node is completely
replaced.
public static void setTagCDATA(org.w3c.dom.Document doc, java.lang.String tag, java.lang.String text)
setTagCDATA
sets the text
in the first
occurence of the tag
in the given
org.w3c.dom.Document
as CDATA section. If the
tag
doesn't exist, nothing happens, otherwise the
corresponding node is completely replaced.
public static void deleteTag(org.w3c.dom.Document doc, java.lang.String tag)
tag
in the given
org.w3c.dom.Document
.
Does nothing if the tag
doesn't exist.
public static org.w3c.dom.Document parseXML(java.lang.String xml, java.lang.String messageName, java.lang.String system) throws XException
XException
public static javax.xml.parsers.DocumentBuilder getDocumentBuilder(java.lang.String messageName, java.lang.String system) throws XException
DocumentBuilder
needed for parsing. For better
performance, DocumentBuilders
are cached per thread. Due
to the message type the parser may be instructed
DocumentBuilder
object for xml parsing
XException
- in case that any problem with instantiating the
DocumentBuilder
object arisespublic static java.lang.String serializeXML(org.w3c.dom.Document doc, java.lang.String systemID) throws XException
doc
- the given org.w3c.dom.Document
to be serializedsystemID
- reference to the DTD of the XML document
XException
public static void setTransformerProperties() throws XException
XException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |