Package javax.xml.parsers

Examples of javax.xml.parsers.DocumentBuilder


            bout.write(b);
        }
        bout.close();
        DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
        fact.setNamespaceAware(true);
        DocumentBuilder db = fact.newDocumentBuilder();
        domDocument = db.parse(new ByteArrayInputStream(bout.toByteArray()));  
        Node n = domDocument.getFirstChild();
        while (n.getChildNodes().getLength() == 0) {
          n = n.getNextSibling();
        }
        n = n.getFirstChild();


    private static Document buildDocument(InputStream is) {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        final Document doc;
        try {
            DocumentBuilder db = dbf.newDocumentBuilder();
            doc = db.parse(is);
        } catch (Exception e) {
            throw new IllegalStateException("buildDocument failed!", e);
        }
        return doc;
    }

                                                    Source.class,
                                                    Service.Mode.PAYLOAD);
        assertNotNull(d);
       
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = dbf.newDocumentBuilder();

        Document document = DOMUtils.readXml(getResourceAsStream("echo-payload.xml"));

        DOMSource source = new DOMSource(document.getDocumentElement());
       

*/
public class XmlUtils {

    public static Document newDocument() {
        try {
            DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            return db.newDocument();
        } catch (Exception e) {
            return null;
        }
    }

       
        @Override
        public void run() {
            try {
              DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                DocumentBuilder db = dbf.newDocumentBuilder();
                FileInputStream fis = new FileInputStream(file);
                Document document = db.parse(fis);
               
                Element eTop = document.getDocumentElement();
               
                String name = Converter.getValidXmlTag(module.getSystemObjectName());
                NodeList nlItems = eTop.getElementsByTagName(name);

   */
  public static Document parseInputStream(final InputStream instream)
      throws ParserConfigurationException, SAXException, IOException
  {
    final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    final DocumentBuilder db = dbf.newDocumentBuilder();
    return db.parse(new InputSource(instream));
  }

  }

  private void compile(File inDir, File outDir, File mapFile, String locale) throws HelpException {
    String xmlFiles[] = inDir.list(new DialogUtils.ExtensionFilter("xml", false));
    Transformer transformer = null;
    DocumentBuilder db = null;
    PrintWriter mapPrinter = null;

    log.debug("generating help file with locale [" + locale + "]");
    try {
      log.debug("loading xml parser ..");
      db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    } catch (Exception e) {
      throw new HelpException("Error while loading an XML parser", e);
    }

    try {
      log.debug("creating map file [" + mapFile.getPath() + "] ..");
      mapPrinter = new PrintWriter(new BufferedOutputStream(new FileOutputStream(mapFile)));
      mapPrinter.println("<?xml version='1.0' encoding='ISO-8859-1' ?>");
      mapPrinter.println(
        "<!DOCTYPE map PUBLIC \"-//Sun Microsystems Inc.//DTD JavaHelp Map Version 1.0//EN\""
          + " \"http://java.sun.com/products/javahelp/map_1_0.dtd\">\n");
      mapPrinter.println("<!-- Do not change, this file is automatically generated -->");
      mapPrinter.println("<map version=\"1.0\">");
    } catch (Exception e) {
      throw new HelpException("Error while creating the map file", e);
    }

    try {
      log.debug("loading transformer ..");
      URL xslFile = getClass().getResource("/resources/xmlgui/help.xsl");
      transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(xslFile.openStream()));
      transformer.setParameter("locale", locale);
    } catch (Exception e) {
      throw new HelpException("Error while constructing the transformer", e);
    }

    for (int i = 0; i < xmlFiles.length; i++) {
      String xmlFile = xmlFiles[i];
      String idName = xmlFile.substring(0, xmlFile.length() - 4);
      File sourceFile = new File(inDir.getPath() + "/" + xmlFile);
      File outputFile = new File(outDir.getPath() + "/" + idName + "." + locale + ".html");
      Document document = null;

      log.debug("loading help file [" + xmlFile + "]");
      try {
        document = db.parse(sourceFile);
        mapPrinter.println(
          "  <mapID target=\""
            + document.getDocumentElement().getAttribute("id")
            + "\" url=\""
            + outputFile.getName()

      fout.close();
     
      //修改配置的配置文件,在其中增加sqlMap元素
      DocumentBuilderFactory factory = DocumentBuilderFactory
      .newInstance();
      DocumentBuilder ibatisConfigBuilder = factory.newDocumentBuilder();
      InputStream inputStream = Resources.getResourceAsStream("SqlMapConfig.xml");
      Document doc = ibatisConfigBuilder.parse(inputStream);
     
      NodeList sqlMapElem = doc.getElementsByTagName("sqlMapConfig");
     
      Element elem = doc.createElement("sqlMap");
      elem.setAttribute("resource", "sqlMap.xml");

        final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setExpandEntityReferences(true);
        final Document doc;
        try {
            DocumentBuilder db = dbf.newDocumentBuilder();
            doc = db.parse(is);
        } catch (Exception e) {
            throw new IllegalStateException("buildDocument failed", e);
        }
        return doc;
    }

        dbf.setNamespaceAware(true);
        dbf.setExpandEntityReferences(true);
        String input = "<doc>" + frag + "</doc>";
        final Document doc;
        try {
            DocumentBuilder db = dbf.newDocumentBuilder();
            doc = db.parse(new ByteArrayInputStream(input.getBytes("UTF-8")));
        } catch (Exception e) {
            throw new IllegalStateException("buildDocument failed", e);
        }
        return doc;
    }

TOP

Related Classes of javax.xml.parsers.DocumentBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.