当前位置: 首页>>代码示例>>Java>>正文


Java LSSerializer.writeToString方法代码示例

本文整理汇总了Java中org.w3c.dom.ls.LSSerializer.writeToString方法的典型用法代码示例。如果您正苦于以下问题:Java LSSerializer.writeToString方法的具体用法?Java LSSerializer.writeToString怎么用?Java LSSerializer.writeToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.w3c.dom.ls.LSSerializer的用法示例。


在下文中一共展示了LSSerializer.writeToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validateXmlResult

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
private void validateXmlResult(Element resultXml) throws KalturaApiException {

        Element resultElement = null;
        try {
            resultElement = XmlUtils.getElementByXPath(resultXml, "/xml/result");
        } catch (XPathExpressionException xee) {
            // AZ (unicon) - necessary in order to debug 
            String resultXmlStr;
            try {
                Document document = resultXml.getOwnerDocument();
                DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation();
                LSSerializer serializer = domImplLS.createLSSerializer();
                resultXmlStr = serializer.writeToString(resultXml);
            } catch (Exception e) {
                resultXmlStr = "Unable to get XML result: "+e;
            }
            throw new KalturaApiException("XPath expression exception ("+xee+") evaluating result:"+resultXmlStr);
        }

        if (resultElement != null) {
            return;            
        } else {
        	throw new KalturaApiException("Invalid result");
        }
    }
 
开发者ID:ITYug,项目名称:kaltura-ce-sakai-extension,代码行数:26,代码来源:KalturaClientBase.java

示例2: main

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.newDocument();

    DOMImplementation impl = document.getImplementation();
    DOMImplementationLS implLS = (DOMImplementationLS) impl.getFeature("LS", "3.0");
    LSSerializer dsi = implLS.createLSSerializer();

    /* We should have here incorrect document without getXmlVersion() method:
     * Such Document is generated by replacing the JDK bootclasses with it's
     * own Node,Document and DocumentImpl classes (see run.sh). According to
     * XERCESJ-1007 the AbstractMethodError should be thrown in such case.
     */
    String result = dsi.writeToString(document);
    System.out.println("Result:" + result);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:AbstractMethodErrorTest.java

示例3: testLSInputParsingString

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
@Test
public void testLSInputParsingString() throws Exception {
    DOMImplementationLS impl = (DOMImplementationLS) getDocumentBuilder().getDOMImplementation();
    String xml = "<?xml version='1.0'?><test>runDocumentLS_Q6</test>";

    LSParser domParser = impl.createLSParser(MODE_SYNCHRONOUS, null);
    LSSerializer domSerializer = impl.createLSSerializer();
    // turn off xml decl in serialized string for comparison
    domSerializer.getDomConfig().setParameter("xml-declaration", Boolean.FALSE);
    LSInput src = impl.createLSInput();
    src.setStringData(xml);
    assertEquals(src.getStringData(), xml);

    Document doc = domParser.parse(src);
    String result = domSerializer.writeToString(doc);

    assertEquals(result, "<test>runDocumentLS_Q6</test>");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:DocumentLSTest.java

示例4: format

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
public static String format(String xml) {

        try {
            final InputSource src = new InputSource(new StringReader(xml));
            final Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement();
            final Boolean keepDeclaration = Boolean.valueOf(xml.startsWith("<?xml"));

            //May need this: System.setProperty(DOMImplementationRegistry.PROPERTY,"com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");


            final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
            final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
            final LSSerializer writer = impl.createLSSerializer();

            writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); // Set this to true if the output needs to be beautified.
            writer.getDomConfig().setParameter("xml-declaration", keepDeclaration); // Set this to true if the declaration is needed to be outputted.

            return writer.writeToString(document);
        } catch (Exception e) {
            return xml;
        }
    }
 
开发者ID:iotoasis,项目名称:SI,代码行数:23,代码来源:Utils.java

示例5: main

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
   ArrayList<LineItem> items = new ArrayList<>();
   items.add(new LineItem(new Product("Toaster", 29.95), 3));
   items.add(new LineItem(new Product("Hair dryer", 24.95), 1));

   ItemListBuilder builder = new ItemListBuilder();
   Document doc = builder.build(items);         
   DOMImplementation impl = doc.getImplementation();
   DOMImplementationLS implLS 
         = (DOMImplementationLS) impl.getFeature("LS", "3.0");
   LSSerializer ser = implLS.createLSSerializer();
   String out = ser.writeToString(doc);      
   
   System.out.println(out);
}
 
开发者ID:shashanksingh28,项目名称:code-similarity,代码行数:17,代码来源:ItemListBuilderDemo.java

示例6: load

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
public void load(File f) throws ConfigPersisterException {
    try {
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		DocumentBuilder builder = factory.newDocumentBuilder();
		Document doc = builder.parse(f);

		DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
	    LSSerializer lsSerializer = domImplementation.createLSSerializer();
	    String configString = lsSerializer.writeToString(doc);

    	_config = (Config) _xstream.fromXML(convertToCurrent(configString));
    	setConfigPath(f);
	} catch (Exception e) {
		throw new ConfigPersisterException(e);
	}
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:17,代码来源:ConfigPersister.java

示例7: formatHtml

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
protected String formatHtml(String html) throws MojoExecutionException {
try {
	InputSource src = new InputSource(new StringReader(html));
	Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement();
	Boolean keepDeclaration = Boolean.valueOf(html.startsWith("<?xml"));
	
	DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
	DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
	LSSerializer writer = impl.createLSSerializer();
	
	writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
	writer.getDomConfig().setParameter("xml-declaration", keepDeclaration);
	
	return writer.writeToString(document);
} catch (Exception e) {
	throw new MojoExecutionException(e.getMessage(), e);
}
  }
 
开发者ID:fastconnect,项目名称:tibco-fcunit,代码行数:19,代码来源:UnitTestsIndexMojo.java

示例8: asString

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
/**
 * Returns a textual representation of an XML Object.
 * 
 * @param doc	XML Dom Document
 * @return	String containing a textual representation of the object
 */
public static String asString(Document doc) {
    try {
        DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
        LSSerializer lsSerializer = domImplementation.createLSSerializer();
        LSOutput lsOutput =  domImplementation.createLSOutput();
        lsOutput.setEncoding("UTF-8");
        return lsSerializer.writeToString(doc);
    } catch (Exception e) {
        e.printStackTrace();
        try {
            DOMSource domSource = new DOMSource(doc);
            StringWriter writer = new StringWriter();
            StreamResult result = new StreamResult(writer);
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer transformer = tf.newTransformer();
            transformer.transform(domSource, result);
            return writer.toString();
        } catch(Exception ex) {
            logger.error(ex);
            return StackTrace.asString(ex);
        }
    }
    
}
 
开发者ID:rovemonteux,项目名称:automation_engine,代码行数:31,代码来源:XMLIO.java

示例9: indentXML

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
/**
* Method to generated idented XML
* Credit: Steve McLeod and DaoWen.
* Code from http://stackoverflow.com/a/11519668
* @param xml input xml in string format
* @return indented xml in string format
*/
  public static String indentXML(String xml) {

      try {
          final InputSource src = new InputSource(new StringReader(xml));
          final Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement();
          final Boolean keepDeclaration = xml.startsWith("<?xml");

      //May need this: System.setProperty(DOMImplementationRegistry.PROPERTY,"com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");


          final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
          final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
          final LSSerializer writer = impl.createLSSerializer();

          writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); // Set this to true if the output needs to be beautified.
          writer.getDomConfig().setParameter("xml-declaration", keepDeclaration); // Set this to true if the declaration is needed to be outputted.

          return writer.writeToString(document);
      } catch (Exception e) {
          throw new RuntimeException(e);
      }
  }
 
开发者ID:raulmrebane,项目名称:LaTeXEE,代码行数:30,代码来源:OutputWriter.java

示例10: nodeToString

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
protected static String nodeToString(Node n, boolean pretty) {
	try {
		final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
		final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
		final LSSerializer writer = impl.createLSSerializer();

		writer.getDomConfig().setParameter("xml-declaration", false);
		if (pretty) {
			writer.getDomConfig().setParameter("format-pretty-print", true);
		}

		return writer.writeToString(n);
	} catch (final Exception e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:17,代码来源:Readability.java

示例11: serialize

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
protected String serialize(Node n) 
			throws ClassNotFoundException,
					InstantiationException,
					IllegalAccessException{
	System.setProperty(DOMImplementationRegistry.PROPERTY,
						"org.apache.xerces.dom.DOMImplementationSourceImpl");
	DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();

	DOMImplementationLS impl = 
			(DOMImplementationLS)registry.getDOMImplementation("LS");

	LSSerializer writer = impl.createLSSerializer();
	String str = writer.writeToString(n);
	
	// sometimes we get processor directives, such as <?xml version="1.0"?>
	// strip these out
	Pattern directivePattern = Pattern.compile("<\\?xml.*$", Pattern.MULTILINE);
	Matcher m = directivePattern.matcher(str);
	str = m.replaceFirst("");
	
	return str;
}
 
开发者ID:BradNeuberg,项目名称:purple-include,代码行数:23,代码来源:QuoteAddress.java

示例12: normalizeXML

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
/**
 * Normalize and pretty-print XML so that it can be compared using string
 * compare. The following code does the following: - Removes comments -
 * Makes sure attributes are ordered consistently - Trims every element -
 * Pretty print the document
 *
 * @param xml The XML to be normalized
 * @return The equivalent XML, but now normalized
 */
public static String normalizeXML(String xml) throws Exception {
    // Remove all white space adjoining tags ("trim all elements")
    xml = xml.replaceAll("\\s*<", "<");
    xml = xml.replaceAll(">\\s*", ">");

    DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
    DOMImplementationLS domLS = (DOMImplementationLS) registry.getDOMImplementation("LS");
    LSParser lsParser = domLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);

    LSInput input = domLS.createLSInput();
    input.setStringData(xml);
    Document document = lsParser.parse(input);

    LSSerializer lsSerializer = domLS.createLSSerializer();
    lsSerializer.getDomConfig().setParameter("comments", Boolean.FALSE);
    lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
    return lsSerializer.writeToString(document);
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:28,代码来源:ModelTestUtils.java

示例13: toString

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
public static String toString( Element element )
{
       DOMImplementation impl = element .getOwnerDocument() .getImplementation();
       if ( impl .hasFeature( "LS", "3.0" ) ){
           DOMImplementationLS lsImpl = (DOMImplementationLS) impl .getFeature("LS", "3.0");
           LSSerializer serializer = lsImpl .createLSSerializer();
           serializer .getDomConfig() .setParameter( "xml-declaration", false ); //by default its true, so set it to false to get String without xml-declaration
           return serializer .writeToString( element );
       }
       else {
           try {
               Transformer transformer = TransformerFactory.newInstance().newTransformer();
               StringWriter stringWriter = new StringWriter();
               transformer.transform(new DOMSource(element), new StreamResult(stringWriter));
               return stringWriter.toString();
           } catch (TransformerException e) {
               e.printStackTrace();
               return "<unableToSerialize/>";
           }
       }
   }
 
开发者ID:vZome,项目名称:vzome-core,代码行数:22,代码来源:DomUtils.java

示例14: format

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
public static String format(String xml) {

        try {
            final InputSource src = new InputSource(new StringReader(xml));
            final Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement();
            final Boolean keepDeclaration = Boolean.valueOf(xml.startsWith("<?xml"));

        //May need this: System.setProperty(DOMImplementationRegistry.PROPERTY,"com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");


            final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
            final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
            final LSSerializer writer = impl.createLSSerializer();

            writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); // Set this to true if the output needs to be beautified.
            writer.getDomConfig().setParameter("xml-declaration", keepDeclaration); // Set this to true if the declaration is needed to be outputted.

            return writer.writeToString(document);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
开发者ID:CloudCycle2,项目名称:YAML_Transformer,代码行数:23,代码来源:Main.java

示例15: readTopics

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
public void readTopics() {

        // extract XML topics from entire XML file
        NodeList topicList = XMLTools.getNodes(new File(System.getProperty(ConfigConstants.TOPICS_FILE)), xTopic);

        // loop over each topic and create topic objects
        for (int i = 0; i < topicList.getLength(); i++) {
            Node topicNode = topicList.item(i);

            // convert back into String representation
            DOMImplementationLS domImplLS = (DOMImplementationLS) topicNode.getOwnerDocument().getImplementation();
            LSSerializer serializer = domImplLS.createLSSerializer();
            String topicString = serializer.writeToString(topicNode);

            // read single topic
            CLEF2011Query topic = readTopic(topicString);

            // store
            this.topics.add(topic);

        }
    }
 
开发者ID:mucke,项目名称:mucke,代码行数:23,代码来源:TopicReader.java


注:本文中的org.w3c.dom.ls.LSSerializer.writeToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。