|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ail.core.XMLString
public class XMLString
This class is designed to do most of the kinds of jobs you are likely to need to do with a string of XML. It doesn't attempt to be a complete replacement for using javax.xml directly, it just takes some of the pain out of the most common usages.
| Constructor Summary | |
|---|---|
XMLString(java.io.File file)
Constructor that builds an XMLString based the contents of the specified file. |
|
XMLString(java.io.InputStream inputStream)
Constructor that builds an XMLString based the docuemnt read from the specified input stream. |
|
XMLString(java.lang.String string)
Constructor that builds an XMLString based upon the specified String. |
|
XMLString(java.net.URL url)
Constructor that builds an XMLString based the contents of the document pointed to by a URL. |
|
| Method Summary | |
|---|---|
java.lang.Object |
clone()
Clone this XMLString object. |
boolean |
equals(java.lang.String xml)
|
boolean |
equals(XMLString xml)
|
java.lang.String |
eval(java.lang.String xpath)
Apply the specified xpath expression to the current XMLString. |
java.lang.String |
eval(XMLString xpath)
Apply the specified xpath expression to the current XMLString. |
java.lang.String |
evalCommand(java.lang.String xpath)
Apply the specified xpath expression to the current XMLString. |
java.lang.String |
evalCommand(XMLString xpath)
Apply the specified xpath expression to the current XMLString. |
void |
evalInline(java.lang.String xpath)
Apply the specified xpath expression to the current XMLString, and replace the current contents of the XMLString with the result. |
void |
evalInline(XMLString xpath)
Apply the specified xpath expression to the current XMLString, and replace the current contents of the XMLString with the result. |
java.lang.String |
evalToText(java.lang.String xpath)
Evaluate an xpath expression to a text value. |
java.lang.String |
evalToText(XMLString xpath)
Evaluate an xpath expression to a text value. |
java.lang.Class |
getType()
Determine the type represented by the xmlString. |
org.w3c.dom.Document |
getXmlDocument()
Return the Document object representing this XMLString. |
java.lang.String |
getXsiType()
Fetch the root elements xsi:type value if there is one, or null if none is present. |
void |
setXMLString(java.io.File file)
Replace the current XMLString with the contents of the specified file. |
void |
setXMLString(java.io.InputStream inputStream)
Replace the current XMLString with the contents of the document read from the specified input stream. |
void |
setXMLString(java.lang.String string)
Replace the current XMLString with the string specified. |
void |
setXMLString(java.lang.StringBuffer sb)
Replace the current XMLString with the string specified. |
void |
setXMLString(java.net.URL url)
Replace the current XMLString with the contents of the document loaded for the specified URL. |
java.lang.String |
toString()
Return the current XML document as a string |
java.lang.String |
toStringWithEntityReferences(boolean excludeBraces)
Similar to toString() but with entity references expanded. |
java.lang.String |
toStringWithoutEntityReferences()
This method does the reverse of toStringWithEntityReferences(boolean). |
java.lang.String |
transform(java.lang.String source)
Apply the specified XSLT to the contents of this XMLString. |
java.lang.String |
transform(XMLString source)
Apply the specified XSLT to the contents of this XMLString. |
void |
transformInline(java.lang.String source)
Apply the specified XSLT to the contents of this XMLString, and replace the XMLString with the result of the transformation. |
void |
transformInline(XMLString source)
Apply the specified XSLT to the contents of this XMLString, and replace the XMLString with the result of the transformation. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public XMLString(java.lang.String string)
string - String in XML format
public XMLString(java.net.URL url)
throws java.io.IOException
url - URL to read document from.
java.io.IOException - if the URL cannot be read.
public XMLString(java.io.File file)
throws java.io.FileNotFoundException,
java.io.IOException
file - The file to read document from.
java.io.FileNotFoundException - if the specified file cannot be found.
java.io.IOException - if the file cannot be read.
public XMLString(java.io.InputStream inputStream)
throws java.io.IOException
inputStream - Stream to read document from.
java.io.IOException - if the input stream cannot be read.| Method Detail |
|---|
public org.w3c.dom.Document getXmlDocument()
throws org.xml.sax.SAXException
org.xml.sax.SAXExceptionpublic void setXMLString(java.lang.StringBuffer sb)
string - String to replace the current string.public void setXMLString(java.lang.String string)
string - String to replace the current string.
public void setXMLString(java.net.URL url)
throws java.io.IOException
url - URL to load XMLString from.
java.io.IOException - If the URL cannot be read.
public void setXMLString(java.io.File file)
throws java.io.FileNotFoundException,
java.io.IOException
file - File to read new string from.
java.io.FileNotFoundException - If file cannot be opened.
java.io.IOException - If an error occurs while reading the file.
public void setXMLString(java.io.InputStream inputStream)
throws java.io.IOException
inputStream - Stream to read the new document from.
java.io.IOException - If an error occurs while reading from the stream.public java.lang.String toString()
toString in class java.lang.Object
public java.lang.String transform(java.lang.String source)
throws javax.xml.transform.TransformerException
source - A string representing the XSLT to apply.
javax.xml.transform.TransformerException - If an error occurs during transformation.
public java.lang.String transform(XMLString source)
throws javax.xml.transform.TransformerException
source - An XMLString representing the XSLT to apply.
javax.xml.transform.TransformerException - If an error occurs during transformation.
public void transformInline(java.lang.String source)
throws javax.xml.transform.TransformerException
source - A string representing the XSLT to apply.
javax.xml.transform.TransformerException - If an error occurs during transformation.
public void transformInline(XMLString source)
throws javax.xml.transform.TransformerException
source - An XMLString representing the XSLT to apply.
javax.xml.transform.TransformerException - If an error occurs during transformation.
public java.lang.String eval(java.lang.String xpath)
throws org.xml.sax.SAXException,
javax.xml.transform.TransformerException
xpath - The query.
org.xml.sax.SAXException
javax.xml.transform.TransformerException
public java.lang.String eval(XMLString xpath)
throws org.xml.sax.SAXException,
javax.xml.transform.TransformerException
xpath - XMLString representing the query
org.xml.sax.SAXException
javax.xml.transform.TransformerException
public java.lang.String evalCommand(java.lang.String xpath)
throws org.xml.sax.SAXException,
javax.xml.transform.TransformerException
eval(String) or eval(XMLString) but
supports commands - which the other methods do not.
xpath - The query.
org.xml.sax.SAXException
javax.xml.transform.TransformerException
public java.lang.String evalCommand(XMLString xpath)
throws org.xml.sax.SAXException,
javax.xml.transform.TransformerException
eval(String) or eval(XMLString) but
supports commands - which the other methods do not.
xpath - XMLString representing the query
org.xml.sax.SAXException
javax.xml.transform.TransformerException
public java.lang.String evalToText(java.lang.String xpath)
throws org.xml.sax.SAXException,
javax.xml.transform.TransformerException
xpath - The xpath expression
org.xml.sax.SAXException
javax.xml.transform.TransformerExceptionevalToText(com.ail.core.XMLString)
public java.lang.String evalToText(XMLString xpath)
throws org.xml.sax.SAXException,
javax.xml.transform.TransformerException
Firstly, if the xpath specified points to an attribute this method will return the value of that attribute, if it points to an element then the element is assumed to be a text element an its value is returned.
For example, an xpath expression of /policy/policy-holder/@forname this
method would return the value of the forname attribute (as eval() would), but given
the xpath /policy/policy-number it would actually evaulate
/policy/policy-number/text() returning the text of the element.
Secondly, this method has special handling for multi-node matches, consider the following xml source doc:
<doc>
<person forename="fred" surname="clucknasty"/>
<person forename="wilma" surname="clucknasty"/>
</doc>
An xpath expression to get both of the forename nodes like this:
/doc/person/@forename
would return 'fredwilma' - which isn't especially useful. This method offers special handling, which allows the following xpath expression:
/doc/person[]/@forname
to return the string 'fred|wilma'.
xpath - The xpath expression
org.xml.sax.SAXException
javax.xml.transform.TransformerException
public void evalInline(java.lang.String xpath)
throws org.xml.sax.SAXException,
javax.xml.transform.TransformerException
xpath - A string representing the query to apply.
org.xml.sax.SAXException
javax.xml.transform.TransformerException
public void evalInline(XMLString xpath)
throws org.xml.sax.SAXException,
javax.xml.transform.TransformerException
xpath - An XMLString representing the query to apply.
org.xml.sax.SAXException
javax.xml.transform.TransformerExceptionpublic boolean equals(java.lang.String xml)
public java.lang.String getXsiType()
public java.lang.Class getType()
throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundExceptionpublic boolean equals(XMLString xml)
public java.lang.Object clone()
clone in class java.lang.Objectpublic java.lang.String toStringWithEntityReferences(boolean excludeBraces)
toString() but with entity references expanded. This simply means
that any characters in the XMLString which have corresponding entity references will be replaced
with them; so if the string contains "<name>Johnson's<name>" this method will
return "<name>Johnson's<name>"
excludeBraces - If false "<" & ">" are replaced with "<" and ">"; otherwise they are left as is.
public java.lang.String toStringWithoutEntityReferences()
toStringWithEntityReferences(boolean).
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||