本文整理汇总了Java中org.jdom2.output.XMLOutputter.outputString方法的典型用法代码示例。如果您正苦于以下问题:Java XMLOutputter.outputString方法的具体用法?Java XMLOutputter.outputString怎么用?Java XMLOutputter.outputString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jdom2.output.XMLOutputter
的用法示例。
在下文中一共展示了XMLOutputter.outputString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStringFromElement
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
/**
*
* @param element
* @param encoding
* @return
*/
public static String getStringFromElement(Element element, String encoding) {
if (element == null) {
throw new IllegalArgumentException("element may not be null");
}
if (encoding == null) {
encoding = DEFAULT_ENCODING;
}
Format format = Format.getRawFormat();
XMLOutputter outputter = new XMLOutputter(format);
Format xmlFormat = outputter.getFormat();
if (StringUtils.isNotEmpty(encoding)) {
xmlFormat.setEncoding(encoding);
}
xmlFormat.setExpandEmptyElements(true);
outputter.setFormat(xmlFormat);
String docString = outputter.outputString(element);
return docString;
}
示例2: writeMuleXmlFile
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
private void writeMuleXmlFile(Element element, VirtualFile muleConfig) {
XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
InputStream inputStream = null;
try {
String outputString = xout.outputString(element);
logger.debug("*** OUTPUT STRING IS " + outputString);
OutputStreamWriter writer = new OutputStreamWriter(muleConfig.getOutputStream(this));
writer.write(outputString);
writer.flush();
writer.close();
} catch (Exception e) {
logger.error("Unable to write file: " + e);
e.printStackTrace();
} finally {
IOUtils.closeQuietly(inputStream);
}
}
示例3: parseString
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
/**
* Parses a JDom2 Object into a string
* @param e
* Object (Element, Text, Document or Attribute)
* @return String
* @author sholzer (11.05.2015)
*/
public String parseString(Object e) {
XMLOutputter element2String = new XMLOutputter();
if (e instanceof Element) {
return element2String.outputString((Element) e);
}
if (e instanceof Text) {
return element2String.outputString((Text) e);
}
if (e instanceof Document) {
return element2String.outputString((Document) e);
}
if (e instanceof org.jdom2.Attribute) {
Attribute a = (org.jdom2.Attribute) e;
return a.getName() + "=\"" + a.getValue() + "\"";
}
return e.toString();
}
示例4: getBackXMLTypeText
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
/**
* 纯文本回复
* @param toName
* @param fromName
* @param content
* @return
*/
public String getBackXMLTypeText(String toName, String fromName,
String content) {
String returnStr = "";
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
String times = format.format(new Date());
Element rootXML = new Element("xml");
rootXML.addContent(new Element("ToUserName").setText(toName));
rootXML.addContent(new Element("FromUserName").setText(fromName));
rootXML.addContent(new Element("CreateTime").setText(times));
rootXML.addContent(new Element("MsgType").setText("text"));
rootXML.addContent(new Element("Content").setText(content));
Document doc = new Document(rootXML);
XMLOutputter XMLOut = new XMLOutputter();
returnStr = XMLOut.outputString(doc);
System.out.println(returnStr);
return returnStr;
}
示例5: createOPFResource
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public static XMLResource createOPFResource(Book book) throws IllegalArgumentException, IllegalStateException
{
Document opfDocument = write(book);
XMLOutputter outputter = new XMLOutputter();
Format xmlFormat = Format.getPrettyFormat();
outputter.setFormat(xmlFormat);
String text = outputter.outputString(opfDocument);
XMLResource resource = null;
try
{
resource = new XMLResource("opf", text.getBytes(Constants.CHARACTER_ENCODING), "OEBPS/content.opf", MediaType.OPF);
}
catch (UnsupportedEncodingException e)
{
//should never happens
}
return resource;
}
示例6: repair
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public static String repair(String originalHtml)
{
String content = null;
try
{
HtmlCleaner cleaner = createHtmlCleaner();
//wir probieren es erstmal mit UTF-8
TagNode rootNode = cleaner.clean(originalHtml);
Document jdomDocument = new JDomSerializer(cleaner.getProperties(), false).createJDom(rootNode);
jdomDocument.setDocType(Constants.DOCTYPE_XHTML.clone());
XMLOutputter outputter = new XMLOutputter();
Format xmlFormat = Format.getPrettyFormat();
outputter.setFormat(xmlFormat);
outputter.setXMLOutputProcessor(new XHTMLOutputProcessor());
content = outputter.outputString(jdomDocument);
}
catch (IllegalAddException e)
{
logger.error("", e);
}
return content;
}
示例7: parseTextConstructToString
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
private String parseTextConstructToString(Element e) {
String value = null;
String type = getAttributeValue(e, "type");
type = (type!=null) ? type : Content.TEXT;
if (type.equals(Content.XHTML) || (type.indexOf("/xml")) != -1 || (type.indexOf("+xml")) != -1) {
// XHTML content needs special handling
XMLOutputter outputter = new XMLOutputter();
List eContent = e.getContent();
Iterator i = eContent.iterator();
while (i.hasNext()) {
org.jdom2.Content c = (org.jdom2.Content) i.next();
if (c instanceof Element) {
Element eC = (Element) c;
if (eC.getNamespace().equals(getAtomNamespace())) {
((Element)c).setNamespace(Namespace.NO_NAMESPACE);
}
}
}
value = outputter.outputString(eContent);
} else {
// Everything else comes in verbatim
value = e.getText();
}
return value;
}
示例8: getXHELM2
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
/**
* method to get xhelm for the helm2 notation with the new functionality
*
* @param helm2notation, HELM2Notation object
* @return xhelm
* @throws MonomerException if monomer is not valid
* @throws JDOMException jdome error
* @throws IOException IO error
* @throws ChemistryException if chemistry engine can not be initialized
*/
public static String getXHELM2(HELM2Notation helm2notation) throws MonomerException, IOException, JDOMException, ChemistryException {
set = new HashSet<Monomer>();
Element root = new Element(xHelmNotationExporter.XHELM_ELEMENT);
Document doc = new Document(root);
Element helmElement = new Element(xHelmNotationExporter.HELM_NOTATION_ELEMENT);
helmElement.setText(helm2notation.toHELM2());
root.addContent(helmElement);
Element monomerListElement = new Element(xHelmNotationExporter.MONOMER_LIST_ELEMENT);
/* save all adhocMonomers */
for (MonomerNotation monomernotation : MethodsMonomerUtils.getListOfMonomerNotation(helm2notation.getListOfPolymers())) {
/* get all elements of an rna */
if (monomernotation instanceof MonomerNotationUnitRNA) {
for (MonomerNotationUnit unit : ((MonomerNotationUnitRNA) monomernotation).getContents()) {
addAdHocMonomer(unit);
}
} else {
addAdHocMonomer(monomernotation);
}
}
/* give the adhocMonomer's information */
for (Monomer distinctmonomer : set) {
Element monomerElement = MonomerParser.getMonomerElement(distinctmonomer);
monomerListElement.getChildren().add(monomerElement);
}
root.addContent(monomerListElement);
XMLOutputter xmlOutput = new XMLOutputter();
// display nice
xmlOutput.setFormat(Format.getPrettyFormat());
return xmlOutput.outputString(doc);
}
示例9: kafToStr
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
/**
* Returns a string containing the XML content of a KAFDocument object.
*/
static String kafToStr(KAFDocument kaf) {
XMLOutputter out = new XMLOutputter(Format.getPrettyFormat().setLineSeparator(LineSeparator.UNIX));
// out.getFormat().setTextMode(Format.TextMode.PRESERVE);
Document jdom = KAFToDOM(kaf);
return out.outputString(jdom);
}
示例10: assertEqualDocumentSerialization
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public static void assertEqualDocumentSerialization(Document expected, Document actual) {
XMLOutputter outputter = new XMLOutputter();
outputter.setFormat(Format.getPrettyFormat());
String expectedAsString = outputter.outputString(expected);
String actualAsString = outputter.outputString(actual);
assertEquals(expectedAsString, actualAsString);
}
示例11: toXML
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public String toXML()
{
Element root = new Element("morph");
Document doc = new Document(root);
doc.getRootElement().addContent(new Element("name").setText( getName() ));
XMLOutputter xmlOut = new XMLOutputter();
xmlOut.setFormat(Format.getPrettyFormat().setOmitDeclaration(true));
return xmlOut.outputString(doc);
}
示例12: toXML
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public String toXML()
{
Element root = new Element("rep");
Document doc = new Document(root);
doc.getRootElement().addContent(new Element("name").setText( getName() ));
doc.getRootElement().addContent(new Element("value").setText( ""+getValue() ));
XMLOutputter xmlOut = new XMLOutputter();
xmlOut.setFormat(Format.getPrettyFormat().setOmitDeclaration(true));
return xmlOut.outputString(doc);
}
示例13: toXML
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public String toXML()
{
Element root = new Element("stat");
Document doc = new Document(root);
doc.getRootElement().addContent(new Element("name").setText( name ));
doc.getRootElement().addContent(new Element("value").setText( ""+value ));
XMLOutputter xmlOut = new XMLOutputter();
xmlOut.setFormat(Format.getPrettyFormat().setOmitDeclaration(true));
return xmlOut.outputString(doc);
}
示例14: toXML
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public String toXML()
{
Element root = new Element("trait");
Document doc = new Document(root);
doc.getRootElement().addContent(new Element("name").setText( getName() ));
doc.getRootElement().addContent(new Element("level").setText( ""+getLevel() ));
XMLOutputter xmlOut = new XMLOutputter();
xmlOut.setFormat(Format.getPrettyFormat().setOmitDeclaration(true));
return xmlOut.outputString(doc);
}
示例15: createNCXResource
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public static Resource createNCXResource(List<Identifier> identifiers, String title, List<Author> authors, TableOfContents tableOfContents) throws IllegalArgumentException, IllegalStateException, IOException
{
Document ncxDocument = write(identifiers, title, authors, tableOfContents);
XMLOutputter outputter = new XMLOutputter();
Format xmlFormat = Format.getPrettyFormat();
outputter.setFormat(xmlFormat);
String text = outputter.outputString(ncxDocument);
Resource resource = MediaType.NCX.getResourceFactory().createResource(NCX_ITEM_ID, text.getBytes(Constants.CHARACTER_ENCODING), DEFAULT_NCX_HREF, MediaType.NCX);
return resource;
}