public class DoNotUseThisXMLUtils
extends java.lang.Object
Constructor and Description |
---|
DoNotUseThisXMLUtils() |
Modifier and Type | Method and Description |
---|---|
static java.util.Enumeration |
childEnumerator(org.w3c.dom.Element parent,
java.lang.String childTag)
Deprecated.
please use the Iterator instead, there's an extra collection here...
|
static java.lang.String |
docToFormattedXML(org.w3c.dom.Document doc) |
static java.lang.String |
encodeString(java.lang.String val)
clean a string, converting entities and characters which might
reasonably trip up an XML parser or XSL processor.
|
static org.w3c.dom.Element |
findChildElement(org.w3c.dom.Element parent,
java.lang.String tagName)
Returns the first XML Element within the Parent of the given tag name.
|
static java.lang.String |
findChildGetItsFirstCDATAText(org.w3c.dom.Element parent,
java.lang.String tag)
Finds the first child element of the given parent and returns the
first CDATA element as a string or null if none there.
|
static java.lang.String |
findChildGetItsText(org.w3c.dom.Element parent,
java.lang.String tag)
Finds the first child element of the given parent and returns the
text element as a String.
|
static java.lang.String |
getAttributeOrChildText(org.w3c.dom.Element parent,
java.lang.String attribTag)
For legacy support, some docs may have an attribute name=value and newer ones have
|
static boolean |
getBooleanAttribute(org.w3c.dom.Element e,
java.lang.String attr,
boolean def)
This method is a handy way to evaluate the value of an attribute as a
boolean value.
|
static java.lang.String |
getChildFirstCDATAText(org.w3c.dom.Element parent)
Finds the first child CData text of a given Element.
|
static java.util.List |
getChildNodeList(org.w3c.dom.Element parent,
boolean immediateChildrenOnly)
Builds a List from the given criteria (wrapping a NodeList)
|
static java.util.List |
getChildNodeList(org.w3c.dom.Element parent,
java.lang.String tag)
Builds a List from the given criteria (wrapping a NodeList)
|
static java.util.List |
getChildNodeList(org.w3c.dom.Element parent,
java.lang.String tag,
boolean immediateChildrenOnly)
Builds a List from the given criteria (wrapping a NodeList)
|
static java.lang.String |
getChildText(org.w3c.dom.Element parent)
Finds he child text of a given Element.
|
static int |
getOcurranceCountFromParent(org.w3c.dom.Element parent,
org.w3c.dom.Element tag)
This method will count how many tags of the same name are "above" the tag you give from the
top of the parent's tree.
|
static org.w3c.dom.Element |
getParentElementOf(org.w3c.dom.Node n)
In parsing XML docs you'll end up iwth Node objects of all kinds, including nested Test stuff, CDATAs,
attributes, etc.
|
static org.w3c.dom.Document |
openXMLDocFromStrBuffer(java.lang.String buffer) |
static java.util.Hashtable |
putElementsInTable(org.w3c.dom.Element parent,
java.lang.String tagName,
java.lang.String keyKey,
java.lang.String valueKey)
example is to get all the properties from the Registry...
|
static java.util.Hashtable |
putNVPairsInTable(org.w3c.dom.Element parent,
java.lang.String tagName)
This method will read all child elements of a parent and read it's child text
a series of name/value pairs, for example:
<Dad key=value key2=value> <Kid ckey=cvalue1>thisKey1=this1&thatKey1=that1</Kid> <Kid ckey=cvalue2>thisKey2=this2&thatKey2=that2</Kid> </Dad> Calling putNVPairsInTable( elDad, "Kid" ) will fill the Hashtable with [this1,thatKey1][this2=thatKey2] |
static java.util.Vector |
readAllSubElementText(org.w3c.dom.Element parent,
java.lang.String tagName)
Gets all the text elements that are children of a given node.
|
static java.util.List |
readChildStrings(org.w3c.dom.Element comp,
java.lang.String wrapTag)
This is a quick way to read a set of simple child tags from a parent.
|
static void |
readIntoMap(org.w3c.dom.Element parent,
java.util.Map map) |
static java.lang.Object |
readObject(org.w3c.dom.Element parent)
This is the companion to the streamMap method above.
|
static void |
streamCDATA(java.io.PrintWriter ps,
java.lang.String tag,
java.lang.String s)
Will write a tag with a sinlge CDATA section in it of the given String
|
static void |
streamCloseTag(java.io.PrintWriter ps,
java.lang.String tagName)
Complement to the streamOpenTag to close a tag you've already opened.
|
static void |
streamListOfStrings(java.io.PrintWriter ps,
java.util.List list,
java.lang.String wrapTag)
This method is the complement of readChildStrings b/c this method will write
a List of Strings (or anything else that has a suitable toString()) and write
the children.
|
static void |
streamMap(java.io.PrintWriter ps,
java.util.Map map)
This method writes the given map (these should be Strings but if they are not we'll write the toString() of them).
|
static void |
streamObject(java.io.PrintWriter ps,
java.lang.String tagName,
java.io.Serializable o)
This method writes a serialized version of an object into the XML stream
The model is like this
|
static void |
streamOpenAndCloseTag(java.io.PrintWriter ps,
java.lang.String tagName,
java.util.Map attribs)
This is a convenience method for writing an open tag that has attributes that will be handled easily
for you.
|
static void |
streamOpenTag(java.io.PrintWriter ps,
java.lang.String tagName)
This is a convenience method for writing an open tag.
|
static void |
streamOpenTag(java.io.PrintWriter ps,
java.lang.String tagName,
java.util.Map attribs)
This is a convenience method for writing an open tag that has attributes that will be handled easily
for you.
|
static void |
streamOpenTag(java.io.PrintWriter ps,
java.lang.String tagName,
java.lang.String attribs)
This is a convenience method for writing an open tag.
|
static void |
streamTagAndChild(java.io.PrintWriter ps,
java.lang.String tag,
java.lang.String s)
Will write a tag with a single child text section in it of the given String
|
static void |
streamTagAndChild(java.io.PrintWriter ps,
java.lang.String tag,
java.lang.String s,
boolean encode)
Will write a tag with a sinlge child text section in it of the given String
|
static void |
streamXMLHeader(java.io.PrintWriter ps) |
static java.util.Hashtable |
stringToProperties(java.lang.String sProperties)
public static Hashtable stringToProperties(String sProperties)
This method knows how to parse a string of key=value[&etc] tokens
into a property table.
|
public static org.w3c.dom.Document openXMLDocFromStrBuffer(java.lang.String buffer) throws java.io.IOException, org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException
java.io.IOException
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
public static java.lang.String docToFormattedXML(org.w3c.dom.Document doc)
public static java.lang.String encodeString(java.lang.String val)
public static org.w3c.dom.Element getParentElementOf(org.w3c.dom.Node n)
n
- the Node object whose parent we wantpublic static org.w3c.dom.Element findChildElement(org.w3c.dom.Element parent, java.lang.String tagName)
Calling findChildElement( elData, "Kid" ) returns an Element for the first Kid.
<Dad key=value key2=value>
<Kid ckey=cvalue1>Some Text</Kid>
<Kid ckey=cvalue2>Some More Text</Kid>
</Dad>
public static java.util.List getChildNodeList(org.w3c.dom.Element parent, java.lang.String tag)
parent
- - the parent Element whose children you want to iterate overtag
- - the tag Name of the children you wantpublic static java.util.List getChildNodeList(org.w3c.dom.Element parent, java.lang.String tag, boolean immediateChildrenOnly)
parent
- - the parent Element whose children you want to iterate overtag
- - the tag Name of the children you wantimmediateChildrenOnly
- - if you only want direct children, not grandchildren/etc, say yes herepublic static java.util.List getChildNodeList(org.w3c.dom.Element parent, boolean immediateChildrenOnly)
parent
- - the parent Element whose children you want to iterate overimmediateChildrenOnly
- - if you only want direct children, not grandchildren/etc, say yes herepublic static java.util.Enumeration childEnumerator(org.w3c.dom.Element parent, java.lang.String childTag)
public static java.lang.String getChildText(org.w3c.dom.Element parent)
If you call getChildText( elKid1 ) you'll get "Some Text" It supports standard child text and CDATA sections.
<Dad key=value key2=value>
<Kid ckey=cvalue1>Some Text</Kid>
<Kid ckey=cvalue2>Some More Text</Kid>
</Dad>
public static void streamMap(java.io.PrintWriter ps, java.util.Map map)
ps
- map
- public static void readIntoMap(org.w3c.dom.Element parent, java.util.Map map)
public static void streamObject(java.io.PrintWriter ps, java.lang.String tagName, java.io.Serializable o) throws java.io.IOException
ps
- o
- java.io.IOException
public static java.lang.Object readObject(org.w3c.dom.Element parent) throws java.io.IOException, java.lang.ClassNotFoundException
parent
- java.io.IOException
java.lang.ClassNotFoundException
public static int getOcurranceCountFromParent(org.w3c.dom.Element parent, org.w3c.dom.Element tag)
parent
- - the parent element to search from. Send Document.getDocumentElement() for the very toptag
- - the Element you want to calculate onpublic static java.lang.String getAttributeOrChildText(org.w3c.dom.Element parent, java.lang.String attribTag)
parent
- attribTag
- public static java.lang.String getChildFirstCDATAText(org.w3c.dom.Element parent)
public static java.lang.String findChildGetItsText(org.w3c.dom.Element parent, java.lang.String tag)
Calling findChildGetItsText( elDad, "Kid" ) returns "Some Text"
<Dad key=value key2=value>
<Kid ckey=cvalue1>Some Text</Kid>
<Kid ckey=cvalue2>Some More Text</Kid>
</Dad>
public static java.lang.String findChildGetItsFirstCDATAText(org.w3c.dom.Element parent, java.lang.String tag)
public static java.util.Hashtable putElementsInTable(org.w3c.dom.Element parent, java.lang.String tagName, java.lang.String keyKey, java.lang.String valueKey)
Calling like putElementsInTable( elDad, "Kid", "cKey", "cValue" ) will fill the Hashtable with [ckey1,v1][ckey2,v2]
<Dad key=value key2=value>
<Kid ckey=ckey1 cValue=v1>Some Text</Kid>
<Kid ckey=ckey2 cValue=v2>Some More Text</Kid>
</Dad>
public static java.util.Hashtable putNVPairsInTable(org.w3c.dom.Element parent, java.lang.String tagName)
Calling putNVPairsInTable( elDad, "Kid" ) will fill the Hashtable with [this1,thatKey1][this2=thatKey2]
<Dad key=value key2=value>
<Kid ckey=cvalue1>thisKey1=this1&thatKey1=that1</Kid>
<Kid ckey=cvalue2>thisKey2=this2&thatKey2=that2</Kid>
</Dad>
public static java.util.Hashtable stringToProperties(java.lang.String sProperties)
This method knows how to parse a string of key=value[&etc] tokens into a property table.
sProperties
- - the string to be parsed, for example
thisKey1=this1&thatKey1
public static java.util.Vector readAllSubElementText(org.w3c.dom.Element parent, java.lang.String tagName)
Calling readAllSubElementText( elDad, "Kid" ) will return a Vector of the Strings [Some Text,Some More Text]
<Dad key=value key2=value>
<Kid ckey=cvalue1>Some Text</Kid>
<Kid ckey=cvalue2>Some More Text</Kid>
</Dad>
public static boolean getBooleanAttribute(org.w3c.dom.Element e, java.lang.String attr, boolean def)
public static java.util.List readChildStrings(org.w3c.dom.Element comp, java.lang.String wrapTag)
<Dad>You'll get back a List of String objects that have SomeInfo and SimMoreInfo if you call this method with the Element object of Dad and the wrapTag of Child
<Child>SomeInfo</Child>
<Child>SomeMoreInfo</Child>
</Dad>
comp
- wrapTag
- public static void streamXMLHeader(java.io.PrintWriter ps)
public static void streamListOfStrings(java.io.PrintWriter ps, java.util.List list, java.lang.String wrapTag)
ps
- list
- wrapTag
- public static void streamOpenTag(java.io.PrintWriter ps, java.lang.String tagName)
ps
- stream you want the tag pushed intotagName
- the name of the tag, w/o any angle brackets!public static void streamOpenTag(java.io.PrintWriter ps, java.lang.String tagName, java.util.Map attribs)
ps
- stream you want the tag pushed intotagName
- the name of the tag, w/o any angle brackets!attribs
- public static void streamOpenAndCloseTag(java.io.PrintWriter ps, java.lang.String tagName, java.util.Map attribs)
ps
- stream you want the tag pushed intotagName
- the name of the tag, w/o any angle brackets!attribs
- public static void streamOpenTag(java.io.PrintWriter ps, java.lang.String tagName, java.lang.String attribs)
ps
- stream you want the tag pushed intotagName
- the name of the tag, w/o any angle brackets!attribs
- if not null, this presumed to be valid XML to put after the tag
name and before the tag close. this should be an attribut list, empty String,
or null. The attribute list must look like "name=value name2=value"
and use quotes for value XML...public static void streamCloseTag(java.io.PrintWriter ps, java.lang.String tagName)
ps
- tagName
- public static void streamCDATA(java.io.PrintWriter ps, java.lang.String tag, java.lang.String s)
public static void streamTagAndChild(java.io.PrintWriter ps, java.lang.String tag, java.lang.String s, boolean encode)
public static void streamTagAndChild(java.io.PrintWriter ps, java.lang.String tag, java.lang.String s)
Copyright © 1998-2014 CA, Inc. All Rights Reserved.