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


Java XMLSerializer类代码示例

本文整理汇总了Java中org.apache.xml.serialize.XMLSerializer的典型用法代码示例。如果您正苦于以下问题:Java XMLSerializer类的具体用法?Java XMLSerializer怎么用?Java XMLSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: XmlEditsVisitor

import org.apache.xml.serialize.XMLSerializer; //导入依赖的package包/类
/**
 * Create a processor that writes to the file named and may or may not
 * also output to the screen, as specified.
 *
 * @param filename Name of file to write output to
 * @param printToScreen Mirror output to screen?
 */
public XmlEditsVisitor(OutputStream out)
    throws IOException {
  this.out = out;
  OutputFormat outFormat = new OutputFormat("XML", "UTF-8", true);
  outFormat.setIndenting(true);
  outFormat.setIndent(2);
  outFormat.setDoctype(null, null);
  XMLSerializer serializer = new XMLSerializer(out, outFormat);
  contentHandler = serializer.asContentHandler();
  try {
    contentHandler.startDocument();
    contentHandler.startElement("", "", "EDITS", new AttributesImpl());
  } catch (SAXException e) {
    throw new IOException("SAX error: " + e.getMessage());
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:24,代码来源:XmlEditsVisitor.java

示例2: save

import org.apache.xml.serialize.XMLSerializer; //导入依赖的package包/类
public void save() throws AtsConfigurationException {

        // save the XML file
        try {
            OutputFormat format = new OutputFormat(doc);
            format.setIndenting(true);
            format.setIndent(4);
            format.setLineWidth(1000);

            XMLSerializer serializer = new XMLSerializer(new FileOutputStream(new File(atsConfigurationFile)),
                                                         format);
            serializer.serialize(doc);
        } catch (Exception e) {
            throw new AtsConfigurationException("Error saving ATS configuration in '" + atsConfigurationFile
                                                + "'", e);
        }
    }
 
开发者ID:Axway,项目名称:ats-framework,代码行数:18,代码来源:AtsProjectConfiguration.java

示例3: convertToXHTML

import org.apache.xml.serialize.XMLSerializer; //导入依赖的package包/类
public static String convertToXHTML(String in) {
    SAXParser parser = new SAXParser();
    InputSource source;
    OutputFormat outputFormat = new OutputFormat();
    try {
        //parser.setProperty("http://cyberneko.org/html/properties/default-encoding", charset);
        parser.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");
        outputFormat.setOmitDocumentType(true);
        outputFormat.setOmitXMLDeclaration(true);
        outputFormat.setMethod(Method.XHTML);
        outputFormat.setIndenting(true);
        StringReader sr = new StringReader(in);
        StringWriter sw = new StringWriter();
        source = new InputSource(sr);
        parser.setContentHandler(new XMLSerializer(sw, outputFormat));
        parser.parse(source);
        return sw.toString();
    } catch (Exception ex) {
        new ExceptionDialog(ex);
    }
    return null;
}
 
开发者ID:cst316,项目名称:spring16project-Team-Laredo,代码行数:23,代码来源:HTMLFileExport.java

示例4: convertToXHTML

import org.apache.xml.serialize.XMLSerializer; //导入依赖的package包/类
public static String convertToXHTML(String in) {       
    SAXParser parser = new SAXParser();
    InputSource source;
    OutputFormat outputFormat = new OutputFormat();
    try {
        //parser.setProperty("http://cyberneko.org/html/properties/default-encoding", charset);
        parser.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");
        outputFormat.setOmitDocumentType(true);
        outputFormat.setOmitXMLDeclaration(true);
        outputFormat.setMethod(Method.XHTML);
        outputFormat.setIndenting(true);            
        StringReader sr = new StringReader(in);
        StringWriter sw = new StringWriter();
        source = new InputSource(sr);
        parser.setContentHandler(new XMLSerializer(sw, outputFormat));
        parser.parse(source);
        return sw.toString();
    }
    catch (Exception ex) {
       new ExceptionDialog(ex);
    }
    return null;
}
 
开发者ID:cst316,项目名称:spring16project-Modula-2,代码行数:24,代码来源:HTMLFileExport.java

示例5: convertToXHTML

import org.apache.xml.serialize.XMLSerializer; //导入依赖的package包/类
public static String convertToXHTML(String in) {
	SAXParser parser = new SAXParser();
	InputSource source;
	OutputFormat outputFormat = new OutputFormat();
	try {
		// parser.setProperty("http://cyberneko.org/html/properties/default-encoding",
		// charset);
		parser.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");
		outputFormat.setOmitDocumentType(true);
		outputFormat.setOmitXMLDeclaration(true);
		outputFormat.setMethod(Method.XHTML);
		outputFormat.setIndenting(true);
		StringReader sr = new StringReader(in);
		StringWriter sw = new StringWriter();
		source = new InputSource(sr);
		parser.setContentHandler(new XMLSerializer(sw, outputFormat));
		parser.parse(source);
		return sw.toString();
	} catch (Exception ex) {
		new ExceptionDialog(ex);
	}
	return null;
}
 
开发者ID:cst316,项目名称:spring16project-Fortran,代码行数:24,代码来源:HTMLFileExport.java

示例6: formatDocumentForTesting

import org.apache.xml.serialize.XMLSerializer; //导入依赖的package包/类
/**
* Cette méthode permet de reformater le contenu d'une chaîne XML
* et donc de s'affranchir des problèmes liés au formatage (tabulations, espaces, retours chariot, ...).
* 
   * @param document
   * @return une chaîne de caractères "normalisée" créé à partir d'un document Document Object Model
   */
  public String formatDocumentForTesting(Document document) {
      try {
          OutputFormat format = new OutputFormat(document);
          format.setLineWidth(65);
          format.setIndenting(true);
          format.setIndent(2);
          Writer out = new StringWriter();
          XMLSerializer serializer = new XMLSerializer(out, format);
          serializer.serialize(document);

          return out.toString();
      } catch (IOException e) {
          throw new RuntimeException(e);
      }
  }
 
开发者ID:fastconnect,项目名称:tibco-fcunit,代码行数:23,代码来源:FCDiff.java

示例7: writeXMLFile

import org.apache.xml.serialize.XMLSerializer; //导入依赖的package包/类
public void writeXMLFile(String out_fName){

		try{
			BufferedWriter out=  new BufferedWriter(new FileWriter(out_fName));
			StringWriter  stringOut = new StringWriter();        //Writer will be a String

			OutputFormat    format  = new OutputFormat(rootDoc);   //Serialize DOM
            XMLSerializer    serial = new XMLSerializer(stringOut, format );
            serial.asDOMSerializer();                            // As a DOM Serializer

            serial.serialize( rootDoc.getDocumentElement() );

            out.write(stringOut.toString() ); //Spit out DOM as a String
			out.close();
        } catch ( Exception ex ) {
            ex.printStackTrace();
        }
	}
 
开发者ID:SOCR,项目名称:HTML5_WebSite,代码行数:19,代码来源:XMLtree.java

示例8: store

import org.apache.xml.serialize.XMLSerializer; //导入依赖的package包/类
/**
   * store loaded data to xml file
* @throws SearchException
   */
  protected final synchronized void store() throws SearchException {
      //Collection.Key[] keys=collections.keys();
      Iterator<Key> it = collections.keyIterator();
      Key k;
  	while(it.hasNext()) {
  		k=it.next();
          Element collEl = getCollectionElement(k.getString());
          SearchCollection sc = getCollectionByName(k.getString());
          setAttributes(collEl,sc);  
      }

      OutputFormat format = new OutputFormat(doc, null, true);
format.setLineSeparator("\r\n");
format.setLineWidth(72);
OutputStream os=null;
try {
    XMLSerializer serializer = new XMLSerializer(os=IOUtil.toBufferedOutputStream(searchFile.getOutputStream()), format);
	serializer.serialize(doc.getDocumentElement());
} catch (IOException e) {
    throw new SearchException(e);
}
finally {
	IOUtil.closeEL(os);
}
  }
 
开发者ID:lucee,项目名称:Lucee4,代码行数:30,代码来源:SearchEngineSupport.java

示例9: validate

import org.apache.xml.serialize.XMLSerializer; //导入依赖的package包/类
public static void validate(
    Document doc,
    String schemaLocationPropertyValue,
    EntityResolver resolver)
    throws IOException,
    SAXException
{
    OutputFormat format  = new OutputFormat(doc, null, true);
    StringWriter writer = new StringWriter(1000);
    XMLSerializer serial = new XMLSerializer(writer, format);
    serial.asDOMSerializer();
    serial.serialize(doc);
    String docString = writer.toString();

    validate(docString, schemaLocationPropertyValue, resolver);
}
 
开发者ID:OSBI,项目名称:mondrian,代码行数:17,代码来源:XmlUtil.java

示例10: save

import org.apache.xml.serialize.XMLSerializer; //导入依赖的package包/类
public static void save(Writer writer, Document document)
    throws IOException
{
    OutputFormat outputFormat = new OutputFormat(document);

    outputFormat.setIndenting(true);

    outputFormat.setLineWidth(Integer.MAX_VALUE);

    outputFormat.setLineSeparator(Util.nl);

    try {
        XMLSerializer serializer = new XMLSerializer(writer, outputFormat);

        serializer.serialize(document);
    } finally {
        if (writer != null) {
            writer.close();
        }
    }
}
 
开发者ID:OSBI,项目名称:mondrian,代码行数:22,代码来源:XmlUtility.java

示例11: serialize

import org.apache.xml.serialize.XMLSerializer; //导入依赖的package包/类
public static String serialize(XmlSerializable serializable)
    throws IOException {
    StringWriter out = new StringWriter();
    try {
        Document doc = BUILDER_FACTORY.newDocumentBuilder().newDocument();
        doc.appendChild(serializable.toXml(doc));
        
        OutputFormat format = new OutputFormat("xml", "UTF-8", true);
        XMLSerializer serializer =
            new XMLSerializer(out, format);
        serializer.setNamespaces(true);
        serializer.asDOMSerializer().serialize(doc);

        return out.toString();
    } catch (ParserConfigurationException e) {
        throw new CosmoParseException(e);
    }
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:19,代码来源:XmlSerializer.java

示例12: printToFile

import org.apache.xml.serialize.XMLSerializer; //导入依赖的package包/类
/**
 * This method uses Xerces specific classes
 * prints the XML document to file.
    */
private void printToFile(){

	try
	{
		//print
		OutputFormat format = new OutputFormat(dom);
		format.setIndenting(true);

		//to generate output to console use this serializer
		//XMLSerializer serializer = new XMLSerializer(System.out, format);


		//to generate a file output use fileoutputstream instead of system.out
		XMLSerializer serializer = new XMLSerializer(
		new FileOutputStream(new File("book.xml")), format);

		serializer.serialize(dom);

	} catch(IOException ie) {
	    ie.printStackTrace();
	}
}
 
开发者ID:FracturedPlane,项目名称:GpsdInspector,代码行数:27,代码来源:XMLCreatorExample.java

示例13: addXMLNameSpace

import org.apache.xml.serialize.XMLSerializer; //导入依赖的package包/类
private byte[] addXMLNameSpace(Document xmlDoc,
                               String nameSpace) {

    Node node = xmlDoc.getDocumentElement();
    Element element = (Element) node;

    element.setAttribute("xmlns", nameSpace);

    OutputFormat outputFormat = new OutputFormat(xmlDoc);
    outputFormat.setOmitDocumentType(true);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    XMLSerializer serializer = new XMLSerializer(out, outputFormat);
    try {
        serializer.asDOMSerializer();
        serializer.serialize(xmlDoc.getDocumentElement());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return out.toByteArray();
}
 
开发者ID:VU-libtech,项目名称:OLE-INST,代码行数:23,代码来源:B2BParserHelper.java

示例14: formatXml

import org.apache.xml.serialize.XMLSerializer; //导入依赖的package包/类
/**
 * This function will format the XML profile with intends and new lines.
 *
 * @param xmlToFormat the xml String you want to format
 * @return the formated version of teh given XML string
 */
private String formatXml(String xmlToFormat) {
    try {
        final Document document = generateXmlDocument(xmlToFormat);

        OutputFormat format = new OutputFormat(document);
        format.setLineWidth(65);
        format.setIndenting(true);
        format.setIndent(2);
        format.setOmitXMLDeclaration(true);
        Writer out = new StringWriter();
        XMLSerializer serializer = new XMLSerializer(out, format);
        serializer.serialize(document);

        return out.toString();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:customertimes,项目名称:easyrec-PoC,代码行数:25,代码来源:ProfileRenderer.java

示例15: addXMLNameSpace

import org.apache.xml.serialize.XMLSerializer; //导入依赖的package包/类
private byte[] addXMLNameSpace(Document xmlDoc,
                               String nameSpace){
    
    Node node = xmlDoc.getDocumentElement();
    Element element = (Element)node;
    
    element.setAttribute("xmlns", nameSpace);
    
    OutputFormat outputFormat = new OutputFormat(xmlDoc);
    outputFormat.setOmitDocumentType(true);
    
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    XMLSerializer serializer = new XMLSerializer( out,outputFormat );
    try {
        serializer.asDOMSerializer();
        serializer.serialize( xmlDoc.getDocumentElement());
    }
    catch (IOException e) {
        throw new RuntimeException(e);
    }
    
    return out.toByteArray();
}
 
开发者ID:kuali,项目名称:kfs,代码行数:24,代码来源:B2BParserHelper.java


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