public class XMLGrep extends Object
Constructor and Description |
---|
XMLGrep()
Creates an instance of a XML
|
Modifier and Type | Method and Description |
---|---|
static void |
changePath(ArrayList<Pair> list,
String match,
String set)
Change the path for each pair in a list using
a pattern.
|
static int |
findFirstElement(ArrayList<Pair> list,
String xpath,
int startAt)
Find the first item that has an XPath that begins with a given XPath.
|
int |
findFirstElement(String xpath,
int startAt)
Find the first item that has an XPath that begins with a given XPath.
|
static int |
findLastElement(ArrayList<Pair> list,
String xpath,
int startAt)
Find the last item that has an XPath that begins with a given XPath.
|
int |
findLastElement(String xpath,
int startAt)
Find the last item that has an XPath that begins with a given XPath.
|
static ArrayList<Integer> |
getChildNodeIndex(ArrayList<Pair> list,
String xpath)
Finds the index of all child nodes at a given XPath.
|
static ArrayList<String> |
getChildNodeNames(ArrayList<Pair> list,
String xpath)
Finds the names of all child nodes at a given XPath.
|
static ArrayList<Node> |
getChildNodes(Node node)
Generate an xpath/value list of pairs.
|
static String |
getFirstValue(ArrayList<Pair> list,
String xpath,
String defaultValue)
Finds the first value that has an XPath which matches a given pattern.
|
String |
getFirstValue(String xpath,
String defaultValue)
Finds the first value that has an XPath which matches a given pattern.
|
static ArrayList<Node> |
getNode(Node node)
Find the Node with the given XPath
|
static ArrayList<Pair> |
getPairs(ArrayList<Pair> list,
String xpath)
Finds all pairs that have an XPath which matches a given pattern.
|
static ArrayList<Pair> |
getSegment(ArrayList<Pair> list,
int startAt,
int endAt)
Extract a copy of a portion of a ArrayList.
|
ArrayList<Pair> |
getSegment(int startAt,
int endAt)
Extract a copy of a portion of a ArrayList.
|
static ArrayList<String> |
getValues(ArrayList<Pair> list,
String xpath)
Finds all values that have an XPath which matches a given pattern.
|
ArrayList<String> |
getValues(String xpath)
Finds all values that have an XPath which matches a given pattern.
|
static ArrayList<String> |
getWords(ArrayList<Pair> list)
Get a list of words in the resource.
|
static boolean |
isCommonWord(String value)
Determine if a word is a common word.
|
static void |
main(String[] args)
Entry point for testing
|
static void |
makeIndex(ArrayList<Pair> list,
Node node,
String xpath)
Generate an xpath/value index.
|
static ArrayList<Pair> |
makeIndex(Node node,
String xpath)
Generate an xpath/value/node index.
|
Document |
open(String pathName)
Parses a file containing XML into its constitute elements.
|
static Document |
parse(InputStream stream)
Parses a file containing XML into its constitute elements.
|
static Document |
parse(String pathName)
Parses a file containing XML into its constitute elements.
|
static Document |
parseString(String text)
Parses a string containing XML into its constitute elements.
|
void |
showHelp()
Display help information.
|
static void |
writeTagged(Node node)
Prints the XML document to the currently defined System.out.
|
static void |
writeTagged(PrintStream out,
ArrayList<Pair> list)
Prints the list of XPath/Value pairs to a @link{PrintStream}
|
static void |
writeTagged(PrintStream out,
ArrayList<Pair> list,
int startAt,
int endAt)
Prints the list of XPath/Value pairs to a @link{PrintStream}
|
static void |
writeTagged(PrintStream out,
ArrayList<Pair> list,
int startAt,
int endAt,
String pattern)
Prints the list of XPath/Value pairs to a @link{PrintStream}
|
static void |
writeTagged(PrintStream out,
ArrayList<Pair> list,
String pattern)
Prints the list of XPath/Value pairs to a @link{PrintStream}
|
static void |
writeTagged(PrintStream out,
Node node)
Prints the XML document to a @link{PrintStream}
Each node is labeled with its XPath.
|
static void |
writeTagged(PrintStream out,
Pair<String,String> item)
Prints an XPath/Value pair to a @link{PrintStream}
|
static void |
writeTagged(PrintStream out,
Pair<String,String> item,
String pattern)
Prints an XPath/Value pair to a @link{PrintStream}
|
static void |
writeXMLTagged(Node node)
Prints the XML document to the currently define System.out.
|
static void |
writeXMLTagged(PrintStream out,
ArrayList<Pair> list)
Prints the list of XPath/Value pairs to a @link{PrintStream}
|
static void |
writeXMLTagged(PrintStream out,
ArrayList<Pair> list,
int startAt,
int endAt)
Prints the list of XPath/Value pairs to a @link{PrintStream}
|
static void |
writeXMLTagged(PrintStream out,
ArrayList<Pair> list,
int startAt,
int endAt,
String pattern)
Prints the list of XPath/Value pairs to a @link{PrintStream}
|
static void |
writeXMLTagged(PrintStream out,
ArrayList<Pair> list,
String pattern)
Prints the list of XPath/Value pairs to a @link{PrintStream}
|
static void |
writeXMLTagged(PrintStream out,
Node node)
Prints the XML document to a @link{PrintStream}
Each node is labeled with its XPath.
|
static void |
writeXMLTagged(PrintStream out,
Pair<String,String> item,
boolean indent)
Prints an XPath/Value pair to a @link{PrintStream}
|
public static void main(String[] args)
public void showHelp()
public Document open(String pathName) throws Exception
pathName
- the fully qualified path and name of the file to parse.Exception
public static Document parse(String pathName) throws Exception
pathName
- the fully qualified path and name of the file to parse.Exception
public static Document parseString(String text) throws Exception
text
- the String containing the XML text.true
if the file could be opened;
false
otherwise.Exception
public static Document parse(InputStream stream) throws Exception
stream
- a connection to a pre-opened file.Exception
public static void makeIndex(ArrayList<Pair> list, Node node, String xpath)
list
- The Arraylist of triplet elements to populate.node
- the starting Node in the Document.xpath
- the XPath to the starting node.public static ArrayList<Pair> makeIndex(Node node, String xpath)
node
- the starting Node in the Document.xpath
- the XPath to the starting node.public static ArrayList<Node> getChildNodes(Node node)
node
- the starting Node in the Document.public static ArrayList<Node> getNode(Node node)
node
- the starting Node in the Document.public String getFirstValue(String xpath, String defaultValue)
xpath
- The XPath of the value to look for.
The XPath can contain regular expressions.defaultValue
- the default value to return if no matching item is found.public static String getFirstValue(ArrayList<Pair> list, String xpath, String defaultValue)
list
- a list of XPath/Value pairs.xpath
- The XPath of the value to look for.
The XPath can contain regular expressions.defaultValue
- the default value to return if no matching item is found.public ArrayList<String> getValues(String xpath)
xpath
- The XPath of the value to look for.
The XPath can contain regular expressions.public static ArrayList<String> getValues(ArrayList<Pair> list, String xpath)
list
- a list of XPath/Value pairs.xpath
- The XPath of the value to look for.
The XPath can contain regular expressions.public static ArrayList<Pair> getPairs(ArrayList<Pair> list, String xpath)
list
- a list of XPath/Value pairs.xpath
- The XPath of the value to look for.
The XPath can contain regular expressions.public static ArrayList<String> getWords(ArrayList<Pair> list)
list
- a list of XPath/Value pairs.public static void changePath(ArrayList<Pair> list, String match, String set)
list
- a list of XPath/Value pairs.match
- a regular expression for the portion of the path to change.set
- the value to substitute for the matched pattern.public static boolean isCommonWord(String value)
public static ArrayList<String> getChildNodeNames(ArrayList<Pair> list, String xpath)
list
- a list of XPath/Value pairs.xpath
- The XPath of the value to look for.
The XPath can contain regular expressions.public static ArrayList<Integer> getChildNodeIndex(ArrayList<Pair> list, String xpath)
list
- a list of XPath/Value pairs.xpath
- The XPath of the value to look for.
The XPath can contain regular expressions.public ArrayList<Pair> getSegment(int startAt, int endAt)
startAt
- the index to start the extract.endAt
- the index to end the extract.public static ArrayList<Pair> getSegment(ArrayList<Pair> list, int startAt, int endAt)
list
- a list of XPath/Value pairs.startAt
- the index to start the extract.endAt
- the index to end the extract.public int findFirstElement(String xpath, int startAt)
xpath
- The XPath pattern of the value to look for.startAt
- the index to start the search.public static int findFirstElement(ArrayList<Pair> list, String xpath, int startAt)
list
- a list of XPath/Value pairs.xpath
- The XPath pattern of the value to look for.startAt
- the index to start the search.public int findLastElement(String xpath, int startAt)
xpath
- The XPath pattern of the value to look for.startAt
- the index to start the search.public static int findLastElement(ArrayList<Pair> list, String xpath, int startAt)
list
- a list of XPath/Value pairs.xpath
- The XPath pattern of the value to look for.startAt
- the index to start the search.public static void writeXMLTagged(Node node)
node
- the starting Node in the document to print.public static void writeXMLTagged(PrintStream out, Node node)
out
- the @link{PrintStream} to send the output.node
- the starting Node in the document to print.public static void writeXMLTagged(PrintStream out, ArrayList<Pair> list, int startAt, int endAt, String pattern)
out
- the @link{PrintStream} to send the output.list
- the list of pairs to print.startAt
- the index of the first pair to print.endAt
- the index of the last pair to print.pattern
- the regex for matching content. If null no checking is done.public static void writeXMLTagged(PrintStream out, ArrayList<Pair> list, int startAt, int endAt)
out
- the @link{PrintStream} to send the output.list
- the list of pairs to print.startAt
- the index of the first pair to print.endAt
- the index of the last pair to print.public static void writeXMLTagged(PrintStream out, ArrayList<Pair> list, String pattern)
out
- the @link{PrintStream} to send the output.list
- the list of pairs to print.pattern
- the regex for matching content. If null no checking is done.public static void writeXMLTagged(PrintStream out, ArrayList<Pair> list)
out
- the @link{PrintStream} to send the output.list
- the list of pairs to print.public static void writeXMLTagged(PrintStream out, Pair<String,String> item, boolean indent)
out
- the @link{PrintStream} to send the output.item
- the XPath/Value pair to print.indent
- if true then tag is indented to match nesting level.public static void writeTagged(Node node)
node
- the starting Node in the document to print.public static void writeTagged(PrintStream out, Node node)
out
- the @link{PrintStream} to send the output.node
- the starting Node in the document to print.public static void writeTagged(PrintStream out, ArrayList<Pair> list, int startAt, int endAt, String pattern)
out
- the @link{PrintStream} to send the output.list
- the list of pairs to print.startAt
- the index of the first pair to print.endAt
- the index of the last pair to print.pattern
- the regex for matching content. If null no checking is done.public static void writeTagged(PrintStream out, ArrayList<Pair> list, int startAt, int endAt)
out
- the @link{PrintStream} to send the output.list
- the list of pairs to print.startAt
- the index of the first pair to print.endAt
- the index of the last pair to print.public static void writeTagged(PrintStream out, ArrayList<Pair> list, String pattern)
out
- the @link{PrintStream} to send the output.list
- the list of pairs to print.pattern
- the regex for matching content. If null no checking is done.public static void writeTagged(PrintStream out, ArrayList<Pair> list)
out
- the @link{PrintStream} to send the output.list
- the list of pairs to print.public static void writeTagged(PrintStream out, Pair<String,String> item, String pattern)
out
- the @link{PrintStream} to send the output.item
- the XPath/Value pair to print.pattern
- the regex for matching content. If null no checking is done.public static void writeTagged(PrintStream out, Pair<String,String> item)
out
- the @link{PrintStream} to send the output.item
- the XPath/Value pair to print.Copyright © 2008-2015 Regents University of California. All Rights Reserved.