本文整理汇总了Java中org.apache.xml.serialize.XMLSerializer.asDOMSerializer方法的典型用法代码示例。如果您正苦于以下问题:Java XMLSerializer.asDOMSerializer方法的具体用法?Java XMLSerializer.asDOMSerializer怎么用?Java XMLSerializer.asDOMSerializer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xml.serialize.XMLSerializer
的用法示例。
在下文中一共展示了XMLSerializer.asDOMSerializer方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: 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);
}
示例3: 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();
}
示例4: 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();
}
示例5: getDocument
import org.apache.xml.serialize.XMLSerializer; //导入方法依赖的package包/类
public String getDocument() {
OutputFormat of = new OutputFormat("XML", "ISO-8859-1", true);
of.setIndent(1);
of.setIndenting(true);
// of.setDoctype(null, "users.dtd");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
XMLSerializer serializer = new XMLSerializer(ps, of);
try {
serializer.asDOMSerializer();
serializer.serialize(doc.getDocumentElement());
ps.close();
return baos.toString();
}
catch (IOException e) {
return null;
}
}
示例6: dropXmlFile
import org.apache.xml.serialize.XMLSerializer; //导入方法依赖的package包/类
protected String dropXmlFile(Person person, org.w3c.dom.Document xmldoc) {
// determine file paths and names
String filename = getBatchFilePathAndName(person);
// setup the file stream
FileOutputStream fos = null;
try {
fos = new FileOutputStream(filename);
try {
// setup the output format
OutputFormat of = new OutputFormat("XML", "UTF-8", true);
of.setIndent(1);
of.setIndenting(true);
// setup the xml serializer and do the serialization
Element docElement = xmldoc.getDocumentElement();
XMLSerializer serializer = new XMLSerializer(fos, of);
serializer.asDOMSerializer();
serializer.serialize(docElement);
} finally {
// close the output stream
if (fos != null) {
fos.close();
}
}
}
catch (IOException e) {
throw new RuntimeException("Exception while writing customer invoice writeoff xml file.", e);
}
return filename;
}
示例7: asByteArray
import org.apache.xml.serialize.XMLSerializer; //导入方法依赖的package包/类
public byte[] asByteArray(Element element) throws IOException {
ByteArrayOutputStream bis = new ByteArrayOutputStream();
OutputFormat format = new OutputFormat(element.getOwnerDocument());
XMLSerializer serializer = new XMLSerializer(
bis, format);
serializer.asDOMSerializer();
serializer.serialize(element);
return bis.toByteArray();
}
示例8: asByteArray
import org.apache.xml.serialize.XMLSerializer; //导入方法依赖的package包/类
public static byte[] asByteArray(Element element) throws IOException {
ByteArrayOutputStream bis = new ByteArrayOutputStream();
OutputFormat format = new OutputFormat(element.getOwnerDocument());
XMLSerializer serializer = new XMLSerializer(
bis, format);
serializer.asDOMSerializer();
serializer.serialize(element);
return bis.toByteArray();
}
示例9: formatWCTPClientQuery
import org.apache.xml.serialize.XMLSerializer; //导入方法依赖的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();
}
示例10: subscriberExists
import org.apache.xml.serialize.XMLSerializer; //导入方法依赖的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;
}