Package javax.xml.transform.dom

Examples of javax.xml.transform.dom.DOMSource


      try { writer.close(); } catch (Exception ignored) { }
    }
  }

  public static void writeDocumentToFile(final File outFile, final Document doc) {
    final Source source = new DOMSource(doc);
    final Result result = new StreamResult(outFile);

    // Write the DOM document to the file
    Transformer xformer;
    try {
View Full Code Here


      t.setOutputProperty(OutputKeys.INDENT, "yes");                            // insert newlines
      t.setOutputProperty(OutputKeys.METHOD, "xml");
      t.setOutputProperty(OutputKeys.VERSION, "1.0");
      t.setOutputProperty(OutputKeys.ENCODING, "utf-8");
      t.setOutputProperty(OutputKeys.STANDALONE, "yes");
      Source src  = new DOMSource(doc);
      File sysDir = new File(WebappHelper.getUserDataRoot(), SYSTEM_DIR);        // destination is .../olatdata/system/catalog.xml
      File f = new File(sysDir, XML_FILE);
      File o = new File(sysDir, XML_FILE + ".old");
      OutputStream os = new BufferedOutputStream(new FileOutputStream(o));
      try {
View Full Code Here

        // Write the DOM back to file
        try
        {
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer m = tf.newTransformer();
            DOMSource source = new DOMSource(doc);
            FileOutputStream os = new FileOutputStream(fileUrl.getFile());
            StreamResult result = new StreamResult(os);
            m.setOutputProperty(OutputKeys.INDENT, "yes");
            m.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, XMLAutoStarterEntityResolver.PUBLIC_ID_KEY);
            m.transform(source, result);
View Full Code Here

            /* Caller still has access to stream/reader; no need to
             * force auto-close-input
             */
            autoCloseInput = cfg.willAutoCloseInput();
        } else if (src instanceof DOMSource) {
            DOMSource domSrc = (DOMSource) src;
            // SymbolTable not used by the DOM-based 'reader':
            return WstxDOMWrappingReader.createFrom(domSrc, cfg);
        } else {
            throw new IllegalArgumentException("Can not instantiate Stax reader for XML source type "+src.getClass()+" (unrecognized type)");
        }
View Full Code Here

        documentBuilderFactory.setNamespaceAware(true);
        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        URL wsdlUri = getClass().getResource("test.wsdl");
        Document wsdl = documentBuilder.parse(wsdlUri.openStream());
        String wsdlSystemId = wsdlUri.toExternalForm();
        DOMSource source = new DOMSource(wsdl);
        source.setSystemId(wsdlSystemId);

        LocalController controller = new LocalController();
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        wsdlgrammar = WSDLSchemaReader.read(source, factory, controller);
View Full Code Here

            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setNamespaceAware(true);
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc = db.parse(new InputSource(new StringReader(contents)));
           
            return (XMLStreamReader2) f.createXMLStreamReader(new DOMSource(doc));
        } catch (Exception e) {
            throw new XMLStreamException(e);
        }
    }
View Full Code Here

            "<root>Some <![CDATA[content]]> in cdata</root>";

        Document doc = parseDomDoc(XML, true);
        XMLInputFactory2 ifact = getInputFactory();
        setCoalescing(ifact, true);
        XMLStreamReader sr = ifact.createXMLStreamReader(new DOMSource(doc));
        assertTokenType(START_DOCUMENT, sr.getEventType());
        assertTokenType(START_ELEMENT, sr.next());
        assertEquals("root", sr.getLocalName());
        assertTokenType(CHARACTERS, sr.next());
        assertEquals("Some content in cdata", getAndVerifyText(sr));
View Full Code Here

            "<root><![CDATA[...]]></root>";
            ;
        Document doc = parseDomDoc(XML, true);
        XMLInputFactory2 ifact = getInputFactory();
        setCoalescing(ifact, true);
        XMLStreamReader sr = ifact.createXMLStreamReader(new DOMSource(doc));
        assertTokenType(START_ELEMENT, sr.next());
        assertEquals("root", sr.getLocalName());
        // Should always be of type CHARACTERS, even if underlying event is CDATA
        assertTokenType(CHARACTERS, sr.next());
        assertEquals("...", getAndVerifyText(sr));
View Full Code Here

    public void testDomInternProperties()
        throws Exception
    {
        Document doc = parseDomDoc("<root />", true);
        XMLInputFactory2 ifact = getInputFactory();
        XMLStreamReader2 sr = (XMLStreamReader2) ifact.createXMLStreamReader(new DOMSource(doc));

        boolean okSet = sr.setProperty(XMLInputFactory2.P_INTERN_NAMES, Boolean.TRUE);
        assertTrue(okSet);
        assertEquals(Boolean.TRUE, sr.getProperty(XMLInputFactory2.P_INTERN_NAMES));
        okSet = sr.setProperty(XMLInputFactory2.P_INTERN_NAMES, Boolean.FALSE);
View Full Code Here

        /* Ok, so: let's first ensure that local names ARE intern()ed
         * when we request them to be:
         */
        ifact.setProperty(XMLInputFactory2.P_INTERN_NAMES, Boolean.TRUE);
        XMLStreamReader sr = ifact.createXMLStreamReader(new DOMSource(doc));
        assertTokenType(START_ELEMENT, sr.next());
        assertEquals(ELEM, sr.getLocalName());
        assertSame(ELEM, sr.getLocalName());

        assertEquals(ATTR, sr.getAttributeLocalName(0));
        assertSame(ATTR, sr.getAttributeLocalName(0));

        assertEquals(PREFIX, sr.getPrefix());
        assertSame(PREFIX, sr.getPrefix());
        sr.close();

        /* And then also that the impl does honor disabling of
         * the feature: while optional, ref. impl. makes this
         * easy so there's no excuse not to.
         */
        ifact.setProperty(XMLInputFactory2.P_INTERN_NAMES, Boolean.FALSE);
        sr = ifact.createXMLStreamReader(new DOMSource(doc));
        assertTokenType(START_ELEMENT, sr.next());
        assertEquals(ELEM, sr.getLocalName());
        // Xerces won't force intern() of element names
        assertNotSame(ELEM, sr.getLocalName());

View Full Code Here

TOP

Related Classes of javax.xml.transform.dom.DOMSource

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.