當前位置: 首頁>>代碼示例>>Java>>正文


Java Document.createCDATASection方法代碼示例

本文整理匯總了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());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:XMLUtilTest.java

示例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;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:19,代碼來源:TransactionStep.java

示例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;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:20,代碼來源:SequenceStep.java

示例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);
			}
		}
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:27,代碼來源:SessionSetObjectStep.java

示例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;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:23,代碼來源:Transaction.java

示例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;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:18,代碼來源:RequestableObject.java

示例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;
}
 
開發者ID:EixoX,項目名稱:jetfuel,代碼行數:15,代碼來源:XmlCdataAdapter.java

示例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());
           }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:MakeNBM.java

示例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;
}
 
開發者ID:convertigo,項目名稱:convertigo-eclipse,代碼行數:14,代碼來源:DesignDocumentViewTreeObject.java

示例10: formatTextExpression

import org.w3c.dom.Document; //導入方法依賴的package包/類
public static Node formatTextExpression(String text, Document document){
    return document.createCDATASection(text.trim());
}
 
開發者ID:NVIvanov,項目名稱:jrbuilder,代碼行數:4,代碼來源:ReportUtil.java

示例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);
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:14,代碼來源:GetJavaSystemProperties.java

示例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);
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:11,代碼來源:ServiceUtils.java

示例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;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:28,代碼來源:XMLUtils.java

示例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());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:Bug6354955.java

示例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]);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:Bug4915748.java


注:本文中的org.w3c.dom.Document.createCDATASection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。