|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectspase.parser110.XMLParser
public class XMLParser
An example XML parser.
| Constructor Summary | |
|---|---|
XMLParser()
Creates an instance of a XML |
|
| Method Summary | |
|---|---|
void |
dumpData(java.io.PrintStream out)
Dump the CData sections of the XML |
static void |
dumpList(java.lang.String label,
java.util.ArrayList<java.lang.String> list)
Print a list of values. |
void |
dumpNode(java.io.PrintStream out,
org.w3c.dom.Node node)
Dump the nodes of the XML |
org.w3c.dom.Node |
findNode(org.w3c.dom.Node node,
java.lang.String name)
Find the next node with the given name. |
java.util.ArrayList<java.lang.String> |
getAllValues(java.lang.String path)
Return the list of values of a member given the XPath like reference to the member. |
static java.lang.String |
getBranchText(org.w3c.dom.Node node)
Concatenate all the text under a node. |
java.lang.String |
getClassName()
|
static javax.xml.transform.stream.StreamSource |
getDefaultStyleSheet()
Obtain a StreamSource to the default XML Style Sheet. |
org.w3c.dom.Document |
getDocument()
Obtain the Document containing the representation of the parsed XML files. |
java.lang.String |
getElementPath(java.lang.String base,
int key)
Construct an element path. |
java.lang.String |
getMemberName(java.lang.String name)
Extract the member name from a string. |
XMLParser |
getMemberNode(java.lang.String name)
Locates a node in a structure based on the the "name" associated with the member. |
int |
getMemberNodeIndex(java.lang.String name)
Extracts the index portion of node reference. |
java.lang.String |
getMemberNodeName(java.lang.String name)
Extracts the name portion of node reference. |
XMLParser |
getMemberParent(java.lang.String name)
Find the parent class for a member. |
java.util.ArrayList<XMLParser> |
getNodes(java.lang.String path)
Return the list of nodes of a member given the XPath like reference to the member. |
java.util.ArrayList<XMLParser> |
getNodes(java.lang.String path,
boolean alwaysOne)
Return the list of nodes of a member given the XPath like reference to the member. |
java.util.ArrayList<XMLParser> |
getNodes(XMLParser parent,
java.lang.String name)
Return the list of nodes given the name of the member. |
static java.lang.String |
getNodeText(org.w3c.dom.Node node)
Concatenate all the text under a node. |
java.lang.String |
getPath()
Return the path to the parsed document |
java.lang.String |
getPathName()
Return the pathname of the parsed document |
java.io.StringReader |
getStringReader()
Return a StringReader for an XML representation of the document. |
static java.lang.String |
getTagClose(int level,
java.lang.String tagName)
Return an close tag with the proper indentation. |
static java.lang.String |
getTaggedList(int level,
java.lang.String tagName,
java.util.ArrayList<java.lang.String> list)
Return a list of tagged values, properly indented. |
static java.lang.String |
getTaggedValue(int level,
java.lang.String tagName,
java.lang.String value)
Return a value enclosed in a tag and properly indented. |
static java.lang.String |
getTagOpen(int level,
java.lang.String tagName)
Return an open tag with the proper indentation. |
XMLParser |
getTopParent(java.lang.String name)
Find the top level parent class for a member. |
java.util.ArrayList<java.lang.String> |
getValues(java.lang.String path)
Return the list of values of a member given the XPath like reference to the member. |
java.util.ArrayList<java.lang.String> |
getValues(java.lang.String path,
boolean alwaysOne)
Return the list of values of a member given the XPath like reference to the member. |
java.lang.String |
getXMLDocument(int n)
Return a string containing an XML representation of this isntance. |
java.lang.String |
getXMLDocument(int n,
java.lang.String path,
int key)
Return a string containing an XML representation of this isntance. |
static java.lang.String |
indent(int level)
Return a string with spaces to format to indicated indentation level. |
boolean |
isInList(java.lang.String base,
java.lang.String value,
java.util.ArrayList list,
int index)
Determine if a list is of the proper type and the index is within the range of the list. |
boolean |
isMatch(java.lang.String base,
java.lang.String value)
Return a list of tagged values, properly indented. |
void |
load(org.w3c.dom.Document document,
java.lang.String root)
Parses a Document which contains a parsed XML file
and set internal variables with the contents of the file. |
void |
load(java.lang.String pathName)
Parses a file containing XML into its constitute elments and sets internal variables with the contents of the file. |
void |
load(java.lang.String pathName,
java.lang.String root)
Parses a file containing XML into its constitute elments and sets internal variables with the contents of the file. |
static void |
main(java.lang.String[] args)
Entry point for testing |
void |
makeEditNodes()
Create an instance of all nodes for use when editing. |
void |
makeNewMember(java.lang.String name)
Create a new member. |
java.lang.String |
makeTagContent(java.lang.String tag,
java.lang.String content)
Return a string with content enclosed in tags with the passed name. |
boolean |
parseXML(java.io.InputStream stream)
Parses a file containing XML into its constitute elments. |
boolean |
parseXML(java.lang.String pathName)
Parses a file containing XML into its constitute elments. |
void |
printXML(java.io.PrintStream out)
Generates an XML representation of the label and stream it to the print stream. |
void |
processNode(org.w3c.dom.Node node)
Walk the nodes of the Document and populate the resource classes. |
void |
removeMember(java.lang.String name,
int index)
Remove an elment of a member. |
void |
setClassName(java.lang.String name)
|
void |
setMember(java.lang.String name,
org.w3c.dom.Node value)
Call the set() method with a given name suffix and a DOM Node
as an argument. |
java.lang.String |
setMember(java.lang.String name,
java.lang.String value)
Call the set() method with a given name suffix and a String
as an argument. |
void |
setMember(java.lang.String name,
java.lang.String[] value)
Call the set() method with a given name suffix and an array of String
values as an argument. |
static java.lang.String |
toImproperCase(java.lang.String value)
Convert a string to "improper" case (make first letter lower case). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public XMLParser()
| Method Detail |
|---|
public static void main(java.lang.String[] args)
public void load(java.lang.String pathName)
throws java.lang.Exception
pathName - the fully qualified path and name of the file to parse.
java.lang.Exception
public void load(java.lang.String pathName,
java.lang.String root)
throws java.lang.Exception
pathName - the fully qualified path and name of the file to parse.root - the name of the tag containg elements to process.
java.lang.Exception
public void load(org.w3c.dom.Document document,
java.lang.String root)
throws java.lang.Exception
Document which contains a parsed XML file
and set internal variables with the contents of the file.
document - the Document representation of a parsed XML file.root - the name of the tag containg elements to process.
java.lang.Exception
public boolean parseXML(java.lang.String pathName)
throws java.lang.Exception
pathName - the fully qualified path and name of the file to parse.
true if the file could be opened;
false otherwise.
java.lang.Exception
public boolean parseXML(java.io.InputStream stream)
throws java.lang.Exception
stream - a connection to a pre-opened file.
true if the file could be read;
false otherwise.
java.lang.Exception
public void printXML(java.io.PrintStream out)
throws java.lang.Exception
out - the stream to print the element to.
java.lang.Exception
public void dumpData(java.io.PrintStream out)
throws java.lang.Exception
out - the stream to print the element to.
java.lang.Exception
public void dumpNode(java.io.PrintStream out,
org.w3c.dom.Node node)
out - the stream to print the element to.
public org.w3c.dom.Node findNode(org.w3c.dom.Node node,
java.lang.String name)
throws java.lang.Exception
node - the Node to start at.name - the name of the node to look for.
java.lang.Exceptionpublic static javax.xml.transform.stream.StreamSource getDefaultStyleSheet()
StreamSource which can be used to read the default
style sheet.public org.w3c.dom.Document getDocument()
Document containing the representation of the parsed XML file.
public void processNode(org.w3c.dom.Node node)
throws java.lang.Exception
String".
If such a method is found the text contained by the
element tags is passed to the method. Then a method with the prefix of "set" is
with a parameter of of type "Node" is attempted. If such a method is found
then method is called with the Node representing the element is passed as the argument.
node - the Node.
java.lang.Exception
public java.lang.String setMember(java.lang.String name,
java.lang.String value)
String
as an argument.
value - the String value to set.
public void setMember(java.lang.String name,
java.lang.String[] value)
String
values as an argument.
value - the String value to set.
public void setMember(java.lang.String name,
org.w3c.dom.Node value)
Node
as an argument.
name - the name of the member (suffix for setXXX() method).value - the String value to set.public XMLParser getMemberParent(java.lang.String name)
node - the Node.public XMLParser getTopParent(java.lang.String name)
name - the XPath name for for the member.public java.lang.String getMemberName(java.lang.String name)
node - the Node.public XMLParser getMemberNode(java.lang.String name)
name - the name associated with a member.public java.lang.String getMemberNodeName(java.lang.String name)
name - the name associated with a member.public int getMemberNodeIndex(java.lang.String name)
name - the name associated with a member.public static java.lang.String getNodeText(org.w3c.dom.Node node)
node - the Node.
public static java.lang.String getBranchText(org.w3c.dom.Node node)
throws java.lang.Exception
node - the Node.
java.lang.Exceptionpublic java.lang.String getPathName()
public java.lang.String getPath()
public java.lang.String makeTagContent(java.lang.String tag,
java.lang.String content)
public static java.lang.String indent(int level)
public java.lang.String getXMLDocument(int n)
n - the number of levels to indent the document.
public java.lang.String getXMLDocument(int n,
java.lang.String path,
int key)
n - the number of levels to indent the document.path - the path to the element.key - the index (key) of the element at the path.public void makeNewMember(java.lang.String name)
name - the name of the member to create.public void makeEditNodes()
name - the name of the member to create.
public void removeMember(java.lang.String name,
int index)
name - the name of the member to create.index - the index of the element to remove.public java.util.ArrayList<XMLParser> getNodes(java.lang.String path)
Only returns nodes for items that are nodes.
Always returns a list with at least one entry. If no nodes are found then the returned entry is blank.
public java.util.ArrayList<XMLParser> getNodes(java.lang.String path,
boolean alwaysOne)
Only returns nodes for items that are nodes.
If no nodes are found then the returned list is empty unless alwaysOne is set to true.
public java.util.ArrayList<XMLParser> getNodes(XMLParser parent,
java.lang.String name)
Only returns nodes for items that are nodes.
If no nodes are found then the returned list is empty.
public java.util.ArrayList<java.lang.String> getAllValues(java.lang.String path)
Only returns values for items that return String values.
Always returns a list with at least one entry. If no nodes are found then the returned entry is blank.
public java.util.ArrayList<java.lang.String> getValues(java.lang.String path)
Only returns values for items that return String values.
Always returns a list with at least one entry. If no nodes are found then the returned entry is blank.
public java.util.ArrayList<java.lang.String> getValues(java.lang.String path,
boolean alwaysOne)
Only returns values for items that return String values.
If no nodes are found then the returned list is empty unless alwaysOne is set to true.
public java.io.StringReader getStringReader()
StringReader for an XML representation of the document.
Commonly used to pass the document through an XML stylesheet transformation
using Transform.
public static java.lang.String getTaggedValue(int level,
java.lang.String tagName,
java.lang.String value)
public static java.lang.String getTagOpen(int level,
java.lang.String tagName)
public static java.lang.String getTagClose(int level,
java.lang.String tagName)
public static java.lang.String getTaggedList(int level,
java.lang.String tagName,
java.util.ArrayList<java.lang.String> list)
public boolean isMatch(java.lang.String base,
java.lang.String value)
public java.lang.String getElementPath(java.lang.String base,
int key)
public boolean isInList(java.lang.String base,
java.lang.String value,
java.util.ArrayList list,
int index)
public static java.lang.String toImproperCase(java.lang.String value)
public static void dumpList(java.lang.String label,
java.util.ArrayList<java.lang.String> list)
node - the Node.public void setClassName(java.lang.String name)
public java.lang.String getClassName()
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||