本文整理汇总了Java中org.apache.xml.serialize.OutputFormat.setDoctype方法的典型用法代码示例。如果您正苦于以下问题:Java OutputFormat.setDoctype方法的具体用法?Java OutputFormat.setDoctype怎么用?Java OutputFormat.setDoctype使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xml.serialize.OutputFormat
的用法示例。
在下文中一共展示了OutputFormat.setDoctype方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: XmlEditsVisitor
import org.apache.xml.serialize.OutputFormat; //导入方法依赖的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());
}
}
示例2: 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();
}
示例3: 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;
}