@Test public void strToDocument() { Document document = DomUtil.strToDocument("<root />"); Element element = document.getDocumentElement(); assertThat(element.getTagName(), is("root")); }
public static Document strToDocument(final String strXml) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); try { DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(new InputSource(new StringReader(strXml))); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } return null; }
DomUtil { public static Document strToDocument(final String strXml) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); try { DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(new InputSource(new StringReader(strXml))); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } return null; } }
DomUtil { public static Document strToDocument(final String strXml) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); try { DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(new InputSource(new StringReader(strXml))); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } return null; } private  DomUtil(); }
DomUtil { public static Document strToDocument(final String strXml) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); try { DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(new InputSource(new StringReader(strXml))); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } return null; } private  DomUtil(); static Document getEmptyDocument(); static Document nodeToDocument(final Node node); static Document strToDocument(final String strXml); static Document srcToDocument(final String srcXml); static String nodeToStr(final Node node); }
DomUtil { public static Document strToDocument(final String strXml) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); try { DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(new InputSource(new StringReader(strXml))); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } return null; } private  DomUtil(); static Document getEmptyDocument(); static Document nodeToDocument(final Node node); static Document strToDocument(final String strXml); static Document srcToDocument(final String srcXml); static String nodeToStr(final Node node);  }