info.joseluismartin.xml
Class XMLUtils

java.lang.Object
  extended by info.joseluismartin.xml.XMLUtils

public abstract class XMLUtils
extends Object

XML DOM Utility static lib for XML (Thread safe) Cache the DOM DocumentBuilder in thread local variable.

Author:
Jose Luis Martin - (jlm@joseluismartin.info)

Constructor Summary
XMLUtils()
           
 
Method Summary
static Node copyNode(Node source, Node dest)
          Copy one node to another node.
static String documentToString(Document doc)
          Serialize a Document to a Sring using JAXP without formating
static String elementToString(Element elto)
          Element to String without format
static DocumentBuilder getDocumentBuilder()
          Get a DocumentBuilder from a ThreadLocal variable, Create if null
static Document newDocument()
          Get new instance of DOM Document
static Document newDocument(String xml)
          Get a new org.w3c.Document from xml string (UTF8)
static Document newDocument(String ns, String name)
          Creates a new Document with name and namespace
static Document newDocumentFromFile(String path)
          Get a new org.w3c.Document from files String
static Document newDocumentFromResource(String res)
          Get a org.w3c.Document from resource String
static String prettyDocumentToString(Document doc)
          Serialize a Document to a String using JAXP with identation (4 spaces)
static Element stringToElement(String xml)
          Get a DOM Element from xml string
static ValidationResult validateSchema(Document doc, Schema schema)
          Validate Document on schema
static ValidationResult validateSchema(String xml, Schema schema)
          Validate a Document with schema
 
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

newDocumentFromResource

public static Document newDocumentFromResource(String res)
Get a org.w3c.Document from resource String

Parameters:
res - ResourceString
Returns:
a new org.w3c.Document

newDocumentFromFile

public static Document newDocumentFromFile(String path)
Get a new org.w3c.Document from files String

Parameters:
path - ResourceString
Returns:
a new org.w3c.Document

newDocument

public static Document newDocument(String xml)
Get a new org.w3c.Document from xml string (UTF8)

Parameters:
xml - string with xml
Returns:
a new org.w3c.Document

newDocument

public static Document newDocument()
Get new instance of DOM Document

Returns:
a new instance of DOM Document

getDocumentBuilder

public static DocumentBuilder getDocumentBuilder()
Get a DocumentBuilder from a ThreadLocal variable, Create if null

Returns:
DocumentBuilder

prettyDocumentToString

public static String prettyDocumentToString(Document doc)
Serialize a Document to a String using JAXP with identation (4 spaces)

Parameters:
doc - to serialize
Returns:
xml string

documentToString

public static String documentToString(Document doc)
Serialize a Document to a Sring using JAXP without formating

Parameters:
doc - Document to serialize
Returns:
Strin with serialized doc

elementToString

public static String elementToString(Element elto)
Element to String without format

Parameters:
elto - to serialize
Returns:
serialized elto

stringToElement

public static Element stringToElement(String xml)
Get a DOM Element from xml string

Parameters:
xml - the string to parse
Returns:
a new DOM Element

copyNode

public static Node copyNode(Node source,
                            Node dest)
Copy one node to another node.

Parameters:
source - source Node
dest - destination Node
Returns:
destination Node

newDocument

public static Document newDocument(String ns,
                                   String name)
Creates a new Document with name and namespace

Parameters:
ns - namespace
name - name
Returns:
new Document

validateSchema

public static ValidationResult validateSchema(String xml,
                                              Schema schema)
Validate a Document with schema

Parameters:
xml - to validate
schema - to falidate from
Returns:
a ValidationResult with validation result

validateSchema

public static ValidationResult validateSchema(Document doc,
                                              Schema schema)
Validate Document on schema

Parameters:
doc - to validate
schema - for validation
Returns:
a ValidationResult with validatin result


Copyright © 2012 JDAL. All Rights Reserved.