本文整理匯總了Java中com.sun.org.apache.xml.internal.serialize.OutputFormat.setLineWidth方法的典型用法代碼示例。如果您正苦於以下問題:Java OutputFormat.setLineWidth方法的具體用法?Java OutputFormat.setLineWidth怎麽用?Java OutputFormat.setLineWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.org.apache.xml.internal.serialize.OutputFormat
的用法示例。
在下文中一共展示了OutputFormat.setLineWidth方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: prettyPrint
import com.sun.org.apache.xml.internal.serialize.OutputFormat; //導入方法依賴的package包/類
private static String prettyPrint(String xml, Boolean omitXmlDeclaration) throws IOException, SAXException, ParserConfigurationException {
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = db.parse(new InputSource(new StringReader(xml)));
OutputFormat format = new OutputFormat(doc);
format.setIndenting(true);
format.setIndent(2);
format.setOmitXMLDeclaration(omitXmlDeclaration);
format.setLineWidth(Integer.MAX_VALUE);
Writer outxml = new StringWriter();
XMLSerializer serializer = new XMLSerializer(outxml, format);
serializer.serialize(doc);
return outxml.toString();
}
示例2: formatXml
import com.sun.org.apache.xml.internal.serialize.OutputFormat; //導入方法依賴的package包/類
/**
* Format xml string.
*
* @param uglyXml the ugly xml
* @return the string
*/
public static String formatXml(String uglyXml) {
try {
String xmlHeader= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(uglyXml));
final Document document = db.parse(is);
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().replace(xmlHeader,"");
} catch (Exception e) {
return "";
}
}
示例3: pretify
import com.sun.org.apache.xml.internal.serialize.OutputFormat; //導入方法依賴的package包/類
public static String pretify(String unformattedXml) {
try {
final Document document = parseXmlFile(unformattedXml);
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);
}
}
示例4: getPrettyXml
import com.sun.org.apache.xml.internal.serialize.OutputFormat; //導入方法依賴的package包/類
public static String getPrettyXml(byte[] xml) {
try {
String unformattedXml = new String(xml);
final Document document = parseXmlFile(unformattedXml);
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);
}
}
示例5: formatXml
import com.sun.org.apache.xml.internal.serialize.OutputFormat; //導入方法依賴的package包/類
/**
* Format the given string as xml content.
* @param xml
* @return
*/
public static String formatXml(String xml) {
try {
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder domBuilder = domFactory.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(xml));
Document doc = domBuilder.parse(is);
OutputFormat format = new OutputFormat(doc);
format.setLineWidth(80);
format.setIndent(2);
format.setIndenting(true);
StringWriter out = new StringWriter();
XMLSerializer xmls = new XMLSerializer(out, format);
xmls.serialize(doc);
return out.toString();
} catch (Exception e) {
e.printStackTrace();
}
return xml;
}
示例6: getPrettyPrintFormat
import com.sun.org.apache.xml.internal.serialize.OutputFormat; //導入方法依賴的package包/類
/**
* @return a format object for XML formatting.
*/
@NonNull
private static OutputFormat getPrettyPrintFormat() {
OutputFormat format = new OutputFormat();
format.setLineWidth(120);
format.setIndenting(true);
format.setIndent(4);
format.setEncoding("UTF-8");
format.setOmitComments(true);
return format;
}
示例7: getString
import com.sun.org.apache.xml.internal.serialize.OutputFormat; //導入方法依賴的package包/類
public String getString(Document document, boolean indenting, int indent) throws IOException{
OutputFormat format = new OutputFormat(document);
format.setLineWidth(200);
format.setIndenting(indenting);
format.setIndent(indent);
format.setPreserveEmptyAttributes(true);
format.setEncoding("UTF-8");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLSerializer serializer = new XMLSerializer(baos, format);
serializer.asDOMSerializer();
serializer.serialize(document);
return baos.toString("UTF-8");
}
示例8: write
import com.sun.org.apache.xml.internal.serialize.OutputFormat; //導入方法依賴的package包/類
/**
* Write markers to file.
* @param pMarkers The markers to write out.
* @param pFileName The name of the destination file.
* @throws Exception TODO
*/
public static void write(MapMarker[] pMarkers, String pFileName) throws Exception
{
File lFile = new File(pFileName);
lFile.createNewFile();
Document doc = buildDocument(pMarkers);
OutputFormat format = new OutputFormat(doc);
format.setLineWidth(LINE_WIDTH);
format.setIndenting(true);
format.setIndent(2);
Writer out = new PrintWriter(lFile);
XMLSerializer serializer = new XMLSerializer(out, format);
serializer.serialize(doc);
}
示例9: prettyFormat
import com.sun.org.apache.xml.internal.serialize.OutputFormat; //導入方法依賴的package包/類
public static String prettyFormat(String unformattedXml) {
try {
final Document document = parseXmlFile(unformattedXml);
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);
}
}
示例10: prettyFormat
import com.sun.org.apache.xml.internal.serialize.OutputFormat; //導入方法依賴的package包/類
private static String prettyFormat(String unformattedXml) {
try {
final Document document = parseXmlFile(unformattedXml);
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) {
return unformattedXml;
}
}
示例11: formatXml
import com.sun.org.apache.xml.internal.serialize.OutputFormat; //導入方法依賴的package包/類
static public String formatXml(String xmlText, String prefix)
throws Exception
{
if (xmlText == null)
return xmlText;
Document doc = parseXml(xmlText);
OutputFormat format = new OutputFormat(doc);
format.setLineWidth(120);
format.setIndenting(true);
format.setIndent(4);
Writer out = new StringWriter();
XMLSerializer serializer = new XMLSerializer(out, format);
serializer.serialize(doc);
xmlText = StringUtils.trim(out.toString(), " \r\n");
if (xmlText.startsWith("<?xml")) {
int ind = xmlText.indexOf("?>");
if (ind > 1) {
xmlText = xmlText.substring(ind + 2);
xmlText = StringUtils.trim(xmlText, " \r\n");
}
}
return StringUtils.formatText(xmlText, prefix);
}
示例12: getPrettyPrintFormat
import com.sun.org.apache.xml.internal.serialize.OutputFormat; //導入方法依賴的package包/類
public static OutputFormat getPrettyPrintFormat() {
OutputFormat format = new OutputFormat();
format.setLineWidth(120);
format.setIndenting(true);
format.setIndent(2);
format.setEncoding("UTF-8");
return format;
}