public class XMLUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
FSEP
Separator, for debugging
|
static java.lang.String |
HSEP |
static java.lang.String |
WCS_SCHEMA |
static java.lang.String |
XML_STD_ENCODING |
Constructor and Description |
---|
XMLUtil() |
Modifier and Type | Method and Description |
---|---|
static nu.xom.Document |
buildDocument(java.io.File file)
Build XOM Document from XML file.
|
static nu.xom.Document |
buildDocument(java.lang.String baseURI,
java.io.InputStream in)
Creates a
Document given a input stream. |
static nu.xom.Document |
buildDocument(java.lang.String baseURI,
java.lang.String document)
Build XOM Document from an XML string.
|
static java.util.List<nu.xom.Document> |
buildDocuments(java.util.Collection<java.io.File> files)
Build a collection of documents
|
static java.util.List<nu.xom.Element> |
ch(nu.xom.Element e)
ch (e) --> [c_1,...,c_n], where parent(c_i)=e for all c_i
|
static java.util.List<nu.xom.Element> |
ch(nu.xom.Element e,
java.lang.String name)
ch (e, n) --> [c_1,...,c_n], where parent(c_i)=e and name(c_i)=n for all c_i
|
static java.util.List<nu.xom.Node> |
ch(nu.xom.Node n)
ch (e) --> [c_1,...,c_n], where parent(c_i)=e for all c_i
|
static java.util.List<nu.xom.Node> |
ch(nu.xom.Node n,
java.lang.String name)
ch (e, n) --> [c_1,...,c_n], where parent(c_i)=e and name(c_i)=n for all c_i
|
static java.util.List<nu.xom.Node> |
chex(nu.xom.Node n,
java.lang.String name)
Extract elements.
|
static java.util.List<nu.xom.Element> |
children(nu.xom.Element e,
java.lang.String... names)
ch (e, n) --> [c_1,...,c_n], where parent(c_i)=e and name(c_i)=n for all c_i
|
static nu.xom.Element |
childWithId(nu.xom.Element e,
java.lang.String id) |
static java.util.List<nu.xom.Element> |
collectAll(nu.xom.Element e,
java.lang.String... names)
Collect all children of
e with the given names. |
static java.util.List<nu.xom.Element> |
collectAll(nu.xom.Element e,
java.lang.String prefix,
java.lang.String name,
nu.xom.XPathContext ctx)
Collect all children of
e with the given name. |
static java.util.List<nu.xom.Element> |
collectAllExcept(nu.xom.Element e,
java.lang.String except,
boolean recurse,
java.lang.String... names) |
static java.util.List<nu.xom.Element> |
collectAllWithID(nu.xom.Element e,
java.lang.String id)
Collect all children of
e for which xml:id=id. |
static nu.xom.Element |
collectFirstWithID(nu.xom.Element e,
java.lang.String id)
Collect all children of
e for which xml:id=id. |
static java.util.Set<java.lang.String> |
collectIds(nu.xom.Element e)
Collect all ids in
e |
static org.w3c.dom.Document |
convert(nu.xom.Document n) |
static org.w3c.dom.NodeList |
convert(java.util.List<nu.xom.Node> l)
Converts a list of XOM nodes to an equivalent DOM NodeList
|
static java.util.List<nu.xom.Node> |
convert(org.w3c.dom.NodeList l)
Converts a DOM NodeList to a list of XOM nodes
|
static void |
copyElement(nu.xom.Element from,
nu.xom.Element to)
Deep copy one element to another.
|
static nu.xom.Element |
copyTag(nu.xom.Element e,
java.util.Set<java.lang.String> ignoreAttributes)
Return new element with the same name and attributes as the given element.
|
static nu.xom.Node |
cp(nu.xom.Node n)
cp() --> ,
where ch'!=Element
|
static nu.xom.Attribute |
createXMLAttribute(java.lang.String name,
java.lang.String value)
Shortcut method for creating a XOM Attribute in the XML namespace.
|
static int |
depth(nu.xom.Element e) |
static java.lang.String |
docName(nu.xom.Document doc) |
static java.util.List<nu.xom.Node> |
elch(nu.xom.Node n)
ch (e) --> [c_1,...,c_n], where parent(c_i)=e for all c_i
|
static nu.xom.Element |
firstChild(nu.xom.Element e)
Get the first child
Element of e |
static nu.xom.Element |
firstChild(nu.xom.Element e,
java.lang.String name) |
static nu.xom.Element |
firstChildRecursive(nu.xom.Element e,
java.lang.String name) |
static java.lang.String |
getBaseURI(nu.xom.Document doc) |
static java.lang.String |
getBaseURI(nu.xom.Element e) |
static nu.xom.Element |
getParent(nu.xom.Element el,
java.lang.String name)
Get the first parent element
name of el |
static nu.xom.Element |
getParent(nu.xom.Node el,
java.lang.String... names)
Get the first parent element
name of el |
static java.lang.String |
getRootElementName(java.lang.String xml) |
static java.lang.String |
getText(nu.xom.Element node)
Return the text that some node contains.
|
static java.lang.String |
getXMLID(nu.xom.Element e) |
static java.lang.String |
getXMLIDOrName(nu.xom.Element e) |
static void |
init() |
static boolean |
isFirstTag(java.lang.String xml,
java.lang.String tag) |
static java.lang.String |
newUUID()
Retrieve a type 4 (pseudo randomly generated) UUID.
|
static java.lang.String |
removeAttributes(java.lang.String xml,
java.lang.String[] attributes)
Remove all attributes from the given
xml string |
static java.lang.String |
removeQualifiers(java.lang.String xml)
Remove all qualifiers in an XML code.
|
static java.lang.String |
removeXmlDecl(java.lang.String xml) |
static java.lang.String |
serialize(nu.xom.Document xomDocument)
Serialize a XOM Document.
|
static java.lang.String |
serialize(nu.xom.Document xomDocument,
boolean noPrettyPrint)
Serialize a XOM Document.
|
static void |
serialize(nu.xom.Document xomDocument,
java.io.File file)
Serialize a XOM DOcument
|
static void |
serialize(nu.xom.Document xomDocument,
java.io.File file,
boolean noPrettyPrint)
Serialize a XOM Document without pretty printing the result.
|
static void |
serialize(nu.xom.Document xomDocument,
java.io.OutputStream os)
Serialize a XOM Document.
|
static void |
serialize(nu.xom.Document xomDocument,
java.io.OutputStream os,
boolean noPrettyPrint)
Serialize a XOM Document without pretty printing the result.
|
static <T extends nu.xom.Node> |
substitute(T o,
T n)
Replaces an
o with a new child node. |
static <T extends nu.xom.Node> |
wrap(boolean copy,
java.lang.String prefix,
java.lang.String name,
java.lang.String namespace,
T... n)
Wrap the given list of nodes in a root element
|
public static java.lang.String FSEP
public static java.lang.String HSEP
public static final java.lang.String XML_STD_ENCODING
public static final java.lang.String WCS_SCHEMA
public static void init()
public static nu.xom.Document buildDocument(java.io.File file) throws java.io.IOException, nu.xom.ParsingException
file
- input XML filejava.io.IOException
nu.xom.ParsingException
public static nu.xom.Document buildDocument(java.lang.String baseURI, java.lang.String document) throws java.io.IOException, nu.xom.ParsingException
baseURI
- document
- input XML stringjava.io.IOException
nu.xom.ParsingException
public static nu.xom.Document buildDocument(java.lang.String baseURI, java.io.InputStream in) throws java.io.IOException, nu.xom.ParsingException
Document
given a input stream.
Note: If the input stream to parse contains a DOCTYPE
definition, but the parser can't find the referenced DTD
, then a
FileNotFound
exception is raised discarding the parsing process.
baseURI
- in
- an input streamjava.io.IOException
nu.xom.ParsingException
public static java.util.List<nu.xom.Document> buildDocuments(java.util.Collection<java.io.File> files) throws java.io.IOException, nu.xom.ParsingException
files
- the XML files to buildjava.io.IOException
nu.xom.ParsingException
public static java.lang.String serialize(nu.xom.Document xomDocument) throws java.io.IOException
xomDocument
- the XOM Document to be serializedjava.io.IOException
public static java.lang.String serialize(nu.xom.Document xomDocument, boolean noPrettyPrint) throws java.io.IOException
xomDocument
- the XOM Document to be serializedjava.io.IOException
public static void serialize(nu.xom.Document xomDocument, java.io.OutputStream os) throws java.io.IOException
xomDocument
- the XOM Document to be serializedos
- stream where to write the resultjava.io.IOException
public static void serialize(nu.xom.Document xomDocument, java.io.OutputStream os, boolean noPrettyPrint) throws java.io.IOException
xomDocument
- the XOM Document to be serializedos
- stream where to write the resultjava.io.IOException
public static void serialize(nu.xom.Document xomDocument, java.io.File file) throws java.io.IOException
xomDocument
- the XOM Document to be serializedfile
- the file to which to serializejava.io.IOException
public static void serialize(nu.xom.Document xomDocument, java.io.File file, boolean noPrettyPrint) throws java.io.IOException
xomDocument
- the XOM Document to be serializedjava.io.IOException
public static java.lang.String docName(nu.xom.Document doc)
public static java.lang.String getBaseURI(nu.xom.Element e)
public static java.lang.String getBaseURI(nu.xom.Document doc)
public static int depth(nu.xom.Element e)
e
in the XML treepublic static nu.xom.Attribute createXMLAttribute(java.lang.String name, java.lang.String value)
name
- name of the attributevalue
- value of the attributepublic static void copyElement(nu.xom.Element from, nu.xom.Element to)
from
- the element to be copiedto
- the element to be replacedpublic static nu.xom.Element copyTag(nu.xom.Element e, java.util.Set<java.lang.String> ignoreAttributes)
ignoreAttributes
- set of attributes to ignore when copyingpublic static nu.xom.Node cp(nu.xom.Node n)
public static boolean isFirstTag(java.lang.String xml, java.lang.String tag)
public static java.lang.String getRootElementName(java.lang.String xml)
public static java.lang.String removeXmlDecl(java.lang.String xml)
public static java.lang.String getText(nu.xom.Element node)
public static java.lang.String getXMLID(nu.xom.Element e)
public static java.lang.String getXMLIDOrName(nu.xom.Element e)
public static java.util.List<nu.xom.Element> collectAll(nu.xom.Element e, java.lang.String... names)
e
with the given names.public static java.util.List<nu.xom.Element> collectAllExcept(nu.xom.Element e, java.lang.String except, boolean recurse, java.lang.String... names)
public static java.util.List<nu.xom.Element> collectAll(nu.xom.Element e, java.lang.String prefix, java.lang.String name, nu.xom.XPathContext ctx)
e
with the given name.public static nu.xom.Element childWithId(nu.xom.Element e, java.lang.String id)
e
with the given id
when searched with DFS.public static java.util.List<nu.xom.Element> collectAllWithID(nu.xom.Element e, java.lang.String id)
e
for which xml:id=id.public static nu.xom.Element collectFirstWithID(nu.xom.Element e, java.lang.String id)
e
for which xml:id=id.public static <T extends nu.xom.Node> T substitute(T o, T n)
o
with a new child node. If o
does not have a parent node, then a NoSuchChildException
is thrown.T
- the type parameter to specify the node typeo
- the old noden
- the new nodepublic static java.lang.String removeQualifiers(java.lang.String xml)
xml
- the XML documentpublic static java.lang.String removeAttributes(java.lang.String xml, java.lang.String[] attributes)
xml
stringpublic static <T extends nu.xom.Node> nu.xom.Element wrap(boolean copy, java.lang.String prefix, java.lang.String name, java.lang.String namespace, T... n)
n
- nodes to wrapcopy
- whether to append copies of the nodes. If false then the given nodes are detached!prefix
- root element prefixname
- root element namenamespace
- root element namespacepublic static java.lang.String newUUID()
public static nu.xom.Element firstChild(nu.xom.Element e)
Element
of e
public static nu.xom.Element firstChild(nu.xom.Element e, java.lang.String name)
public static nu.xom.Element firstChildRecursive(nu.xom.Element e, java.lang.String name)
public static java.util.List<nu.xom.Node> ch(nu.xom.Node n)
public static java.util.List<nu.xom.Node> ch(nu.xom.Node n, java.lang.String name)
public static java.util.List<nu.xom.Element> ch(nu.xom.Element e)
public static java.util.List<nu.xom.Element> ch(nu.xom.Element e, java.lang.String name)
public static java.util.List<nu.xom.Element> children(nu.xom.Element e, java.lang.String... names)
public static java.util.List<nu.xom.Node> elch(nu.xom.Node n)
public static java.util.List<nu.xom.Node> chex(nu.xom.Node n, java.lang.String name)
public static nu.xom.Element getParent(nu.xom.Node el, java.lang.String... names)
name
of el
el
- this elementname
- the name of the parent elementpublic static nu.xom.Element getParent(nu.xom.Element el, java.lang.String name)
name
of el
el
- this elementname
- the name of the parent elementpublic static org.w3c.dom.Document convert(nu.xom.Document n)
public static java.util.List<nu.xom.Node> convert(org.w3c.dom.NodeList l)
l
- the DOM NodeListpublic static org.w3c.dom.NodeList convert(java.util.List<nu.xom.Node> l)
l
- the list of XOM nodespublic static java.util.Set<java.lang.String> collectIds(nu.xom.Element e)
e
e
- the given element