本文整理匯總了Java中org.w3c.dom.Document.createCDATASection方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.createCDATASection方法的具體用法?Java Document.createCDATASection怎麽用?Java Document.createCDATASection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.dom.Document
的用法示例。
在下文中一共展示了Document.createCDATASection方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testCDATA
import org.w3c.dom.Document; //導入方法依賴的package包/類
public void testCDATA() throws Exception {
Document doc = XMLUtil.createDocument("root", null, null, null);
Element e = doc.createElement("sometag");
doc.getDocumentElement().appendChild(e);
String cdataContent = "!&<>*\n[[]]";
CDATASection cdata = doc.createCDATASection(cdataContent);
e.appendChild(cdata);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLUtil.write(doc, baos, "UTF-8");
String data = baos.toString("UTF-8").replace("\r\n", "\n");
assertTrue("Can't find CDATA section", data.indexOf("<![CDATA[" + cdataContent + "]]>") != -1);
// parse the data back to DOM
Document doc2 = XMLUtil.parse(new InputSource(new ByteArrayInputStream(baos.toByteArray())), false, false, null, null);
NodeList nl = doc2.getElementsByTagName("sometag");
assertEquals("Wrong number of <sometag/> elements", 1, nl.getLength());
nl = nl.item(0).getChildNodes();
assertEquals("Wrong number of <sometag/> child elements", 1, nl.getLength());
Node child = nl.item(0);
assertTrue("Expecting CDATASection node", child instanceof CDATASection);
assertEquals("Wrong CDATASection content", cdataContent, ((CDATASection) child).getNodeValue());
}
示例2: toXml
import org.w3c.dom.Document; //導入方法依賴的package包/類
@Override
public Element toXml(Document document) throws EngineException {
Element element = super.toXml(document);
// Storing the transaction WSDL type
try {
Element wsdlTypeElement = document.createElement("wsdltype");
if (wsdlType != null) {
CDATASection cDATASection = document.createCDATASection(wsdlType);
wsdlTypeElement.appendChild(cDATASection);
element.appendChild(wsdlTypeElement);
}
} catch (NullPointerException e) {
// Silently ignore
}
return element;
}
示例3: toXml
import org.w3c.dom.Document; //導入方法依賴的package包/類
@Override
public Element toXml(Document document) throws EngineException {
Element element = super.toXml(document);
// Storing the sequence WSDL type
try {
Element wsdlTypeElement = document.createElement("wsdltype");
if (wsdlType != null) {
CDATASection cDATASection = document.createCDATASection(wsdlType);
wsdlTypeElement.appendChild(cDATASection);
element.appendChild(wsdlTypeElement);
}
}
catch(NullPointerException e) {
// Silently ignore
}
return element;
}
示例4: createStepNodeValue
import org.w3c.dom.Document; //導入方法依賴的package包/類
@Override
protected void createStepNodeValue(Document doc, Element stepNode) throws EngineException {
stepNode.setAttribute("key", key.isEmpty() ? "empty_key":StringUtils.normalize(key));
if (!key.isEmpty()) {
Object object = value.getObject(this);
if (object != null) {
if ((object instanceof NodeList) && value.isUseSource()) {
OutputFilter outputFilter = sequence.new OutputFilter(OutputOption.UsefullOnly);
object = Sequence.ouputDomView((NodeList) object,outputFilter);
}
getSequence().context.httpSession.setAttribute(key, object);
// Simple objects
if ((object instanceof Boolean) || (object instanceof Integer) || (object instanceof Double)
|| (object instanceof Float) || (object instanceof Character) || (object instanceof Long)
|| (object instanceof Short) || (object instanceof Byte) || (object instanceof String)) {
stepNode.setTextContent(ParameterUtils.toString(object));
}
// Complex objects
else {
CDATASection cDATASection = doc.createCDATASection(ParameterUtils.toString(object));
stepNode.appendChild(cDATASection);
}
}
}
}
示例5: toXml
import org.w3c.dom.Document; //導入方法依賴的package包/類
@Override
public Element toXml(Document document) throws EngineException {
Element element = super.toXml(document);
// Storing the transaction "default" flag
element.setAttribute("default", new Boolean(isDefault).toString());
// Storing the transaction handlers
try {
Element handlersElement = document.createElement("handlers");
if (handlers != null) {
CDATASection cDATASection = document.createCDATASection(handlers);
handlersElement.appendChild(cDATASection);
element.appendChild(handlersElement);
}
}
catch(NullPointerException e) {
// Silently ignore
}
return element;
}
示例6: toXml
import org.w3c.dom.Document; //導入方法依賴的package包/類
@Override
public Element toXml(Document document) throws EngineException {
Element element = super.toXml(document);
// Storing the transaction WSDL type
try {
Element wsdlTypeElement = document.createElement("wsdltype");
if (wsdlType != null) {
CDATASection cDATASection = document.createCDATASection(wsdlType);
wsdlTypeElement.appendChild(cDATASection);
element.appendChild(wsdlTypeElement);
}
} catch(NullPointerException e) {
// Silently ignore
}
return element;
}
示例7: format
import org.w3c.dom.Document; //導入方法依賴的package包/類
/**
* Appends the formatted CDATA text of the value as a text node to it's
* parent;
*/
public Node format(Object value, Node parent) {
String txt = this.componentAdapter.formatObject(value);
if (txt != null && !txt.isEmpty()) {
Document document = parent.getOwnerDocument();
CDATASection section = document.createCDATASection(txt);
parent.appendChild(section);
return section;
} else
return null;
}
示例8: getTextNode
import org.w3c.dom.Document; //導入方法依賴的package包/類
public org.w3c.dom.Text getTextNode(Document ownerDoc) {
// XXX Current XMLUtil.write anyway does not preserve CDATA sections, it seems.
String nocdata = getProject().getProperty("makenbm.nocdata");
if (nocdata != null && Project.toBoolean(nocdata)) {
return ownerDoc.createTextNode(text.toString());
} else {
return ownerDoc.createCDATASection(text.toString());
}
}
示例9: toXml
import org.w3c.dom.Document; //導入方法依賴的package包/類
@Override
public Element toXml(Document document) {
Element element = document.createElement("view");
element.setAttribute("classname", getClass().getName());
JSONObject jsondata = new JSONObject();
try {
jsondata.put("name", getObject().getName());
jsondata.put("value", getObject().getJSONObject());
} catch (JSONException e) {}
CDATASection cDATASection = document.createCDATASection(jsondata.toString());
element.appendChild(cDATASection);
return element;
}
示例10: formatTextExpression
import org.w3c.dom.Document; //導入方法依賴的package包/類
public static Node formatTextExpression(String text, Document document){
return document.createCDATASection(text.trim());
}
示例11: getServiceResult
import org.w3c.dom.Document; //導入方法依賴的package包/類
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
Element rootElement = document.getDocumentElement();
Properties properties = System.getProperties();
StringBuffer sProperties = new StringBuffer();
for(Object propertyName : new TreeSet<Object>(properties.keySet()))
sProperties.append(propertyName + "=" + properties.getProperty(propertyName.toString()) + "\n");
CDATASection cdata = document.createCDATASection("DATA");
cdata.setData(sProperties.toString());
rootElement.appendChild(cdata);
}
示例12: addMessage
import org.w3c.dom.Document; //導入方法依賴的package包/類
public static void addMessage(Document document, Element root, String message, String tagName, Boolean usingCDATA) {
Element line = document.createElement(tagName);
if (usingCDATA) {
CDATASection cdata = document.createCDATASection(message);
line.appendChild(cdata);
} else {
line.setTextContent(message);
}
root.appendChild(line);
}
示例13: getCDataText
import org.w3c.dom.Document; //導入方法依賴的package包/類
public static String getCDataText(String s) {
String cdataText = "";
try {
if (!s.equals("")) {
Document dom = createDom("java");
Element root = dom.createElement("root");
CDATASection cDATASection = dom.createCDATASection(s);
root.appendChild(cDATASection);
dom.appendChild(root);
cdataText = prettyPrintElement(root, true, true);
cdataText = cdataText.replaceAll("<root>", "");
cdataText = cdataText.replaceAll("</root>", "");
String cdataStart = "<![CDATA[";
if (cdataText.startsWith(cdataStart)) {
int i = cdataText.substring(cdataStart.length()).indexOf(cdataStart);
if (i < 0) {
cdataText = cdataText.replaceAll("<!\\[CDATA\\[", "");
cdataText = cdataText.replaceAll("\\]\\]>", "");
}
}
}
} catch (ParserConfigurationException e) {
}
return cdataText;
}
示例14: testCDATA
import org.w3c.dom.Document; //導入方法依賴的package包/類
@Test
public void testCDATA() {
try {
Document xmlDocument = createNewDocument();
CDATASection cdataNode = xmlDocument.createCDATASection("See Data!!");
String outerXML = getOuterXML(cdataNode);
System.out.println("OuterXML of Comment Node is:" + outerXML);
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Exception occured: " + e.getMessage());
}
}
示例15: testMain
import org.w3c.dom.Document; //導入方法依賴的package包/類
@Test
public void testMain() throws Exception {
final boolean[] hadError = new boolean[1];
DocumentBuilderFactory docBF = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBF.newDocumentBuilder();
Document doc = docBuilder.getDOMImplementation().createDocument("namespaceURI", "ns:root", null);
CDATASection cdata = doc.createCDATASection("text1]]>text2");
doc.getDocumentElement().appendChild(cdata);
DOMConfiguration config = doc.getDomConfig();
DOMErrorHandler erroHandler = new DOMErrorHandler() {
public boolean handleError(DOMError error) {
System.out.println(error.getMessage());
Assert.assertEquals(error.getType(), "cdata-sections-splitted");
Assert.assertFalse(hadError[0], "two errors were reported");
hadError[0] = true;
return false;
}
};
config.setParameter("error-handler", erroHandler);
doc.normalizeDocument();
Assert.assertTrue(hadError[0]);
}