本文整理匯總了Java中org.apache.xml.serialize.OutputFormat.setOmitXMLDeclaration方法的典型用法代碼示例。如果您正苦於以下問題:Java OutputFormat.setOmitXMLDeclaration方法的具體用法?Java OutputFormat.setOmitXMLDeclaration怎麽用?Java OutputFormat.setOmitXMLDeclaration使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.xml.serialize.OutputFormat
的用法示例。
在下文中一共展示了OutputFormat.setOmitXMLDeclaration方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: convertToXHTML
import org.apache.xml.serialize.OutputFormat; //導入方法依賴的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;
}
示例2: convertToXHTML
import org.apache.xml.serialize.OutputFormat; //導入方法依賴的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;
}
示例3: convertToXHTML
import org.apache.xml.serialize.OutputFormat; //導入方法依賴的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;
}
示例4: nodeToString
import org.apache.xml.serialize.OutputFormat; //導入方法依賴的package包/類
protected String nodeToString(Node node) {
StringWriter stringOut = new StringWriter();
OutputFormat format = new OutputFormat(Method.XML, null, false);
format.setOmitXMLDeclaration(true);
NodeXMLSerializer serial = new NodeXMLSerializer(stringOut, format);
try {
serial.serializeNode(node);
} catch (IOException e) {
throw new RuntimeException(e);
}
return stringOut.toString();
}
示例5: formatXml
import org.apache.xml.serialize.OutputFormat; //導入方法依賴的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);
}
}
示例6: extractNoteContent
import org.apache.xml.serialize.OutputFormat; //導入方法依賴的package包/類
/**
* Extracts the node content. Basically returns every character in the
* subsection element.
*
* @param subsection
* the subsection of a rule
* @return the node content
* @throws ParserConfigurationException
* in case of an error
* @throws IOException
* in case of an error
*/
protected String extractNoteContent(final Element subsection) throws ParserConfigurationException,
IOException {
StringWriter writer = new StringWriter();
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.newDocument();
OutputFormat format = new OutputFormat(doc);
format.setOmitXMLDeclaration(true);
XMLSerializer serializer = new XMLSerializer(writer, format);
serializer.serialize(subsection);
String serialized = writer.getBuffer().toString();
serialized = StringUtils.substringAfter(serialized, ">");
return StringUtils.substringBeforeLast(serialized, "<");
}
示例7: prettyDocumentToString
import org.apache.xml.serialize.OutputFormat; //導入方法依賴的package包/類
/**
* Serialize a Document to a String using JAXP with identation (4 spaces)
* @param doc to serialize
* @return xml string
*/
public static String prettyDocumentToString(Document doc) {
StringWriter writer = new StringWriter();
OutputFormat out = new OutputFormat();
out.setOmitXMLDeclaration(true);
out.setIndenting(true);
out.setIndent(4);
out.setLineSeparator(System.getProperty("line.separator"));
out.setLineWidth(Integer.MAX_VALUE);
XMLSerializer serializer = new XMLSerializer(writer, out);
try {
Element rootElement = doc.getDocumentElement();
serializer.serialize(rootElement);
} catch (IOException e) {
log.error(e);
}
return writer.toString();
}
示例8: getTemporaryHandler
import org.apache.xml.serialize.OutputFormat; //導入方法依賴的package包/類
protected SimpleContentHandler getTemporaryHandler(OutputStream st) {
OutputFormat of = new OutputFormat();
of.setPreserveSpace(true);
of.setOmitXMLDeclaration(true);
XMLSerializer tmpSerial = new XMLSerializer(st, of);
return new SimpleContentHandler(tmpSerial);
}
示例9: getTemporaryHandler
import org.apache.xml.serialize.OutputFormat; //導入方法依賴的package包/類
protected SimpleContentHandler getTemporaryHandler(OutputStream st) {
OutputFormat of = new OutputFormat();
of.setPreserveSpace(true);
of.setOmitXMLDeclaration(true);
XMLSerializer tmpSerial = new XMLSerializer(st, of);
SimpleContentHandler tmpHandler = new SimpleContentHandler(tmpSerial);
return tmpHandler;
}
示例10: prettyPrintXML
import org.apache.xml.serialize.OutputFormat; //導入方法依賴的package包/類
public static void prettyPrintXML(InputStream docStream, OutputStream out) throws ParserConfigurationException, SAXException, IOException {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(docStream);
OutputFormat fmt = new OutputFormat(doc);
fmt.setOmitXMLDeclaration(true);
fmt.setLineWidth(72);
fmt.setIndenting(true);
fmt.setIndent(2);
XMLSerializer ser = new XMLSerializer(out, fmt);
ser.serialize(doc);
}
示例11: elementToString
import org.apache.xml.serialize.OutputFormat; //導入方法依賴的package包/類
/**
* Element to String without format
*
* @param elto to serialize
* @return serialized elto
*/
public static String elementToString(Element elto) {
StringWriter writer = new StringWriter();
OutputFormat of = new OutputFormat();
of.setOmitXMLDeclaration(true);
XMLSerializer serializer = new XMLSerializer(writer, of);
serializer.setNamespaces(true);
try {
serializer.serialize(elto);
} catch (IOException ioe) {
log.error(ioe);
}
return writer.toString();
}
示例12: formatWCTPClientQuery
import org.apache.xml.serialize.OutputFormat; //導入方法依賴的package包/類
public String formatWCTPClientQuery(String to, String from,
String trackingNumber) throws DOMException, IOException {
Document doc = new DocumentImpl();
Element root = doc.createElement("wctp-Operation");
// Create Root Element
root.setAttribute("wctpVersion", "wctp-dtd-v1r1");
Element submitClientQuery = doc.createElement("wctp-ClientQuery");
if (username != null) {
submitClientQuery.setAttribute("senderID", username);
} else {
submitClientQuery.setAttribute("senderID", from);
}
if (password != null) {
submitClientQuery.setAttribute("securityCode", password);
}
submitClientQuery.setAttribute("recipientID", to);
submitClientQuery.setAttribute("trackingNumber", trackingNumber);
root.appendChild(submitClientQuery);
// Attach another Element - grandaugther
doc.appendChild(root); // Add Root to Document
OutputFormat format = new OutputFormat(doc); //Serialize DOM
format.setOmitXMLDeclaration(true);
format.setDoctype(null, "http://dtd.wctp.org/wctp-dtd-v1r1.dtd");
StringWriter stringOut = new StringWriter(); //Writer will be a String
XMLSerializer serial = new XMLSerializer(stringOut, format);
serial.asDOMSerializer(); // As a DOM Serializer
serial.serialize(doc.getDocumentElement());
// This is a kludge. Skytel rejects any XML definition with an encoding
// Xerces always uses the encoding. So, I had to kludge around it.
String header = "<?xml version=\"1.0\"?>\n";
// If we need a parameter, use it now
if ((parameter != null) && (parameter.length()>0)){
header = parameter + "=" + header;
}
return header + stringOut.toString();
}
示例13: subscriberExists
import org.apache.xml.serialize.OutputFormat; //導入方法依賴的package包/類
public boolean subscriberExists(String from, String pagerNumber) throws IOException {
String trackingNumber = BrokerFactory.getUUIDBroker().getUUID(from+pagerNumber+System.currentTimeMillis());
Document doc = new DocumentImpl();
Element root = doc.createElement("wctp-Operation");
// Create Root Element
root.setAttribute("wctpVersion", "wctp-dtd-v1r1");
Element lookupSubscriber = doc
.createElement("wctp-LookupSubscriber");
// Create element
Element sender = doc
.createElement("wctp-Originator");
if (username != null) {
sender.setAttribute("senderID", username);
} else {
sender.setAttribute("senderID", from);
}
if (password != null) {
sender.setAttribute("securityCode", password);
}
lookupSubscriber.appendChild(sender);
Element lookupControl = doc.createElement("wctp-LookupMessageControl");
lookupControl.setAttribute("messageID", trackingNumber);
lookupSubscriber.appendChild(lookupControl);
Element recipient = doc.createElement("wctp-Recipient");
recipient.setAttribute("recipientID", pagerNumber);
lookupSubscriber.appendChild(recipient);
root.appendChild(lookupSubscriber);
// Attach another Element - grandaugther
doc.appendChild(root); // Add Root to Document
OutputFormat format = new OutputFormat(doc); //Serialize DOM
format.setOmitXMLDeclaration(true);
format.setDoctype(null, "http://dtd.wctp.org/wctp-dtd-v1r1.dtd");
StringWriter stringOut = new StringWriter(); //Writer will be a String
XMLSerializer serial = new XMLSerializer(stringOut, format);
serial.asDOMSerializer(); // As a DOM Serializer
serial.serialize(doc.getDocumentElement());
// This is a kludge. Skytel rejects any XML definition with an encoding
// Xerces always uses the encoding. So, I had to kludge around it.
String header = "<?xml version=\"1.0\"?>\n";
// If we need a parameter, use it now
if (parameter != null) {
header = parameter + "=" + header;
}
BrokerFactory.getLoggingBroker().logDebug(stringOut.toString());
String response = sendMessage(header + stringOut.toString());
BrokerFactory.getLoggingBroker().logDebug(response);
// Read the response
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(
response)));
NodeList nodeList = document
.getElementsByTagName("wctp-Confirmation");
Element element = (Element) nodeList.item(0);
if (element == null)
return false;
NodeList success = element.getElementsByTagName("wctp-Success");
if (success == null)
return false;
if (success.getLength() < 1) return false;
} catch (Exception e) {
return false;
}
return true;
}