当前位置: 首页>>代码示例>>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;未经允许,请勿转载。