Exemple #1
0
 /**
  * Creates and returns a new Document. The first item that is an element will be set as the root
  * element of the document.
  *
  * @param children the children to add to the document
  * @return a new element
  */
 public static ERXML.Doc doc(ERXML.Item... children) {
   ERXML.Doc doc = ERXML.doc();
   for (ERXML.Item child : children) {
     doc.add(child);
   }
   return doc;
 }
Exemple #2
0
 /**
  * Creates and return a document parsed from the given file.
  *
  * @param file the file to parse from
  * @return a new parsed document
  */
 public static ERXML.Doc doc(File file) {
   try {
     Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file);
     return ERXML.doc(document);
   } catch (Throwable t) {
     throw new IllegalArgumentException("Failed to parse a document from the provided file.", t);
   }
 }
Exemple #3
0
 /**
  * Creates and return a document parsed from the given string.
  *
  * @param documentString the string to parse as XML
  * @return a new parsed document
  */
 public static ERXML.Doc doc(String documentString) {
   try {
     ERXML.Doc doc;
     if (documentString == null || documentString.trim().length() == 0) {
       doc = ERXML.doc();
     } else {
       Document document =
           DocumentBuilderFactory.newInstance()
               .newDocumentBuilder()
               .parse(new InputSource(new StringReader(documentString)));
       doc = ERXML.doc(document);
     }
     return doc;
   } catch (Throwable t) {
     throw new IllegalArgumentException("Failed to parse a document from the provided string.", t);
   }
 }
Exemple #4
0
 /**
  * Creates and return a document parsed from the given reader.
  *
  * @param reader the reader to parse from
  * @return a new parsed document
  */
 public static ERXML.Doc doc(Reader reader) {
   try {
     Document document =
         DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(reader));
     return ERXML.doc(document);
   } catch (Throwable t) {
     throw new IllegalArgumentException("Failed to parse a document from the provided reader.", t);
   }
 }
Exemple #5
0
 /**
  * Converts a W3C Document into an XML.Doc.
  *
  * @param w3cDocument the W3C Document
  * @return the equivalent XML.Doc
  */
 public static ERXML.Doc doc(org.w3c.dom.Document w3cDocument) {
   org.w3c.dom.Element w3cElement = w3cDocument.getDocumentElement();
   Doc doc = ERXML.doc();
   doc.setRoot(ERXML.e(w3cElement));
   return doc;
 }