com.adobe.idml
Class XmlUtils

java.lang.Object
  extended by com.adobe.idml.XmlUtils

public abstract class XmlUtils
extends java.lang.Object

This class contains static methods for working with XML related technologies such as XML, XSL and XPath.


Constructor Summary
XmlUtils()
           
 
Method Summary
static java.lang.String getAttribute(java.util.ArrayList<java.lang.String> files, java.lang.String expr)
          Returns a String containing the result of the xPath expression after it is executed against the XML file.
static java.lang.String getAttribute(org.w3c.dom.NamedNodeMap nm, java.lang.String attrib)
          Returns a String containing the result after searching the element for the attribute name provided.
static java.lang.String getAttribute(java.lang.String xmlFilePath, java.lang.String expr)
          Returns a String containing the result of the xPath expression after it is executed against the XML file.
static java.util.Hashtable<java.lang.String,java.lang.String> getAttributePairsForElement(java.util.ArrayList<java.lang.String> xmlFilePaths, java.lang.String expr, java.lang.String keyAttrib, java.lang.String valueAttrib)
          Returns a HashTable of Strings containing the result of the xPath expression after it is executed against the XML files.
static java.util.Hashtable<java.lang.String,java.lang.String> getAttributePairsForElement(java.lang.String file, java.lang.String expr, java.lang.String keyAttrib, java.lang.String valueAttrib)
          Returns a HashTable of Strings containing the result of the xPath expression after it is executed against the XML file.
static java.util.ArrayList<java.lang.String> getAttributes(java.util.ArrayList<java.lang.String> files, java.lang.String expr)
          Returns a ArrayList of Strings containing the result of the xPath expression after it is executed against the XML file.
static java.util.ArrayList<java.lang.String> getAttributes(java.lang.String xmlFilePath, java.lang.String expr)
          Returns a ArrayList of Strings containing the result of the xPath expression after it is executed against the XML file.
static java.util.ArrayList<java.lang.String> getElements(java.util.ArrayList<java.lang.String> xmlFilePaths, java.lang.String expr)
          Gets an ArrayList of the text content in a group of elements.
static java.util.ArrayList<java.lang.String> getElements(java.lang.String xmlFilePath, java.lang.String expr)
          Gets an ArrayList of the text content in a group of elements.
static org.w3c.dom.Document getExistingXmlDoc(java.lang.String xmlFilePath)
          Get a DOM Document object from an existing file.
static org.w3c.dom.Document getNewDOMDoc()
          Get an empty DOM Document.
static org.w3c.dom.Document getNewXslStylesheet()
          Get an empty XSL version 1.0 document.
static int getNodeListCount(java.lang.String xmlFilePath, java.lang.String expr)
          Get the number of nodes returned by an expression to an XML file.
static org.w3c.dom.NodeList getXPathValue(java.io.File xmlFile, java.lang.String expr)
          Given an XML file and an XPath expression, this method will return a node set containing the results of the query.
static org.w3c.dom.NodeList getXPathValue(java.lang.String xmlFilePath, java.lang.String expr)
          Given an XML file path and an XPath expression, this method will return a node set containing the results of the query.
static void writeXmlFile(org.w3c.dom.Document doc, java.io.File xmlFile)
          Given a file object and an XML DOM Document, this method will write a formatted XML file to disk.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlUtils

public XmlUtils()
Method Detail

writeXmlFile

public static void writeXmlFile(org.w3c.dom.Document doc,
                                java.io.File xmlFile)
                         throws java.io.IOException,
                                javax.xml.parsers.ParserConfigurationException
Given a file object and an XML DOM Document, this method will write a formatted XML file to disk.

Parameters:
doc - The Document object to be written to file.
xmlFile - The file object the Document Object will be written to.
Throws:
java.io.IOException
javax.xml.parsers.ParserConfigurationException

getNewDOMDoc

public static org.w3c.dom.Document getNewDOMDoc()
                                         throws javax.xml.parsers.ParserConfigurationException
Get an empty DOM Document.

Returns:
An empty DOM Document.
Throws:
javax.xml.parsers.ParserConfigurationException

getNewXslStylesheet

public static org.w3c.dom.Document getNewXslStylesheet()
                                                throws javax.xml.parsers.ParserConfigurationException
Get an empty XSL version 1.0 document.

Returns:
An empty XSL version 1.0 document.
Throws:
javax.xml.parsers.ParserConfigurationException

getExistingXmlDoc

public static org.w3c.dom.Document getExistingXmlDoc(java.lang.String xmlFilePath)
                                              throws javax.xml.parsers.ParserConfigurationException,
                                                     java.io.IOException,
                                                     org.xml.sax.SAXException
Get a DOM Document object from an existing file.

Parameters:
xmlFilePath - A path to the XML file.
Returns:
A DOM Document object derived from the XML file provided.
Throws:
javax.xml.parsers.ParserConfigurationException
java.io.IOException
org.xml.sax.SAXException

getXPathValue

public static org.w3c.dom.NodeList getXPathValue(java.lang.String xmlFilePath,
                                                 java.lang.String expr)
                                          throws PackageException,
                                                 java.io.IOException,
                                                 javax.xml.xpath.XPathExpressionException
Given an XML file path and an XPath expression, this method will return a node set containing the results of the query.

Parameters:
xmlFilePath - The XML file to searched.
expr - The xPath expression which will retrieve the required nodes from the XML file.
Returns:
NodeList containing the results of the xPath query.
Throws:
PackageException
java.io.IOException
javax.xml.xpath.XPathExpressionException

getXPathValue

public static org.w3c.dom.NodeList getXPathValue(java.io.File xmlFile,
                                                 java.lang.String expr)
                                          throws PackageException,
                                                 java.io.IOException,
                                                 javax.xml.xpath.XPathExpressionException
Given an XML file and an XPath expression, this method will return a node set containing the results of the query.

Parameters:
xmlFile - The file to be queried.
expr - The expression to query the file.
Returns:
A NodeList containing the results of the query.
Throws:
PackageException
java.io.IOException
javax.xml.xpath.XPathExpressionException

getAttribute

public static java.lang.String getAttribute(org.w3c.dom.NamedNodeMap nm,
                                            java.lang.String attrib)
                                     throws PackageException
Returns a String containing the result after searching the element for the attribute name provided. An Exception is thrown if the attribute is not found. Searches an element for the specific attribute name.

Parameters:
nm - The NamedNodeMap object for the node element.
attrib - The attribute name to search for.
Returns:
The value of the attribute name in the NamedNodeMap object provided.
Throws:
PackageException

getAttribute

public static java.lang.String getAttribute(java.lang.String xmlFilePath,
                                            java.lang.String expr)
                                     throws PackageException,
                                            java.io.IOException,
                                            javax.xml.xpath.XPathExpressionException
Returns a String containing the result of the xPath expression after it is executed against the XML file.

Parameters:
xmlFilePath - The single XML file to searched.
expr - The xPath expression which will retrieve the required nodes from the XML file. The expression should be written to lookup exactly one attribute. Otherwise an Exception will be thrown.
Returns:
String containing the results of the xPath query.
Throws:
PackageException
java.io.IOException
javax.xml.xpath.XPathExpressionException

getAttribute

public static java.lang.String getAttribute(java.util.ArrayList<java.lang.String> files,
                                            java.lang.String expr)
                                     throws PackageException,
                                            java.io.IOException,
                                            javax.xml.xpath.XPathExpressionException
Returns a String containing the result of the xPath expression after it is executed against the XML file.

Parameters:
files - The XML files to searched.
expr - The xPath expression which will retrieve the required nodes from the XML files. The expression should be written to lookup a specific attribute. Otherwise an Exception will be thrown.
Returns:
ArrayList containing the results of the xPath query.
Throws:
PackageException
java.io.IOException
javax.xml.xpath.XPathExpressionException

getNodeListCount

public static int getNodeListCount(java.lang.String xmlFilePath,
                                   java.lang.String expr)
                            throws PackageException,
                                   java.io.IOException,
                                   javax.xml.xpath.XPathExpressionException
Get the number of nodes returned by an expression to an XML file.

Parameters:
xmlFilePath - The path to the XML file to be queried.
expr - The XPath expression to query the file with.
Returns:
The number of nodes returned.
Throws:
PackageException
java.io.IOException
javax.xml.xpath.XPathExpressionException

getAttributes

public static java.util.ArrayList<java.lang.String> getAttributes(java.lang.String xmlFilePath,
                                                                  java.lang.String expr)
                                                           throws PackageException,
                                                                  java.io.IOException,
                                                                  javax.xml.xpath.XPathExpressionException
Returns a ArrayList of Strings containing the result of the xPath expression after it is executed against the XML file. The expression should be written to lookup a specific attribute. Otherwise an InterrogatorException will be thrown.

Parameters:
xmlFilePath - The single XML file to searched.
expr - The xPath expression which will retrieve the required nodes from the XML file.
Returns:
ArrayList containing the results of the xPath query.
Throws:
PackageException
java.io.IOException
javax.xml.xpath.XPathExpressionException

getElements

public static java.util.ArrayList<java.lang.String> getElements(java.lang.String xmlFilePath,
                                                                java.lang.String expr)
                                                         throws PackageException,
                                                                java.io.IOException,
                                                                javax.xml.xpath.XPathExpressionException
Gets an ArrayList of the text content in a group of elements.

Parameters:
xmlFilePath - The path to the XML file to be queried.
expr - The XPath Expression to query the XML file with.
Returns:
An ArrayList of Strings containing the text content of the elements returned by the query.
Throws:
PackageException
java.io.IOException
javax.xml.xpath.XPathExpressionException

getElements

public static java.util.ArrayList<java.lang.String> getElements(java.util.ArrayList<java.lang.String> xmlFilePaths,
                                                                java.lang.String expr)
                                                         throws PackageException,
                                                                java.io.IOException,
                                                                javax.xml.xpath.XPathExpressionException
Gets an ArrayList of the text content in a group of elements.

Parameters:
xmlFilePaths - The paths to the XML files to be queried.
expr - The XPath Expression to query the XML file with.
Returns:
An ArrayList of Strings containing the text content of the elements returned by the query.
Throws:
PackageException
java.io.IOException
javax.xml.xpath.XPathExpressionException

getAttributes

public static java.util.ArrayList<java.lang.String> getAttributes(java.util.ArrayList<java.lang.String> files,
                                                                  java.lang.String expr)
                                                           throws PackageException,
                                                                  java.io.IOException,
                                                                  javax.xml.xpath.XPathExpressionException
Returns a ArrayList of Strings containing the result of the xPath expression after it is executed against the XML file. The expression should be written to lookup a specific attribute. Otherwise an InterrogatorException will be thrown.

Parameters:
files - The XML files to searched.
expr - The xPath expression which will retrieve the required nodes from the XML files.
Returns:
ArrayList containing the results of the xPath query.
Throws:
PackageException
java.io.IOException
javax.xml.xpath.XPathExpressionException

getAttributePairsForElement

public static java.util.Hashtable<java.lang.String,java.lang.String> getAttributePairsForElement(java.lang.String file,
                                                                                                 java.lang.String expr,
                                                                                                 java.lang.String keyAttrib,
                                                                                                 java.lang.String valueAttrib)
                                                                                          throws PackageException,
                                                                                                 java.io.IOException,
                                                                                                 javax.xml.xpath.XPathExpressionException
Returns a HashTable of Strings containing the result of the xPath expression after it is executed against the XML file. The expression should be written to lookup elements. The key and value parameters specify attributes in the the elements which will be loaded into the HashTable has key/value pairs.

Parameters:
file - The single XML file to searched.
expr - The xPath expression which will retrieve the required nodes from the XML files.
keyAttrib - The name of the attribute which will be the key in the HashTable returned.
valueAttrib - The name of the attribute which will be the value in the HashTable returned.
Returns:
HashTable containing the results of the xPath query.
Throws:
PackageException
java.io.IOException
javax.xml.xpath.XPathExpressionException

getAttributePairsForElement

public static java.util.Hashtable<java.lang.String,java.lang.String> getAttributePairsForElement(java.util.ArrayList<java.lang.String> xmlFilePaths,
                                                                                                 java.lang.String expr,
                                                                                                 java.lang.String keyAttrib,
                                                                                                 java.lang.String valueAttrib)
                                                                                          throws PackageException,
                                                                                                 java.io.IOException,
                                                                                                 javax.xml.xpath.XPathExpressionException
Returns a HashTable of Strings containing the result of the xPath expression after it is executed against the XML files. The expression should be written to lookup elements. The key and value parameters specify attributes in the the elements which will be loaded into the HashTable has key/value pairs.

Parameters:
xmlFilePaths - The list of XML files to queried.
expr - The xPath expression which will retrieve the required nodes from the XML files.
keyAttrib - The name of the attribute which will be the key in the HashTable returned.
valueAttrib - The name of the attribute which will be the value in the HashTable returned.
Returns:
HashTable containing the results of the xPath query.
Throws:
PackageException
java.io.IOException
javax.xml.xpath.XPathExpressionException


Copyright © 2008 Adobe Systems Incorporated. All Rights Reserved.