本文整理汇总了Java中org.w3c.dom.Comment类的典型用法代码示例。如果您正苦于以下问题:Java Comment类的具体用法?Java Comment怎么用?Java Comment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Comment类属于org.w3c.dom包,在下文中一共展示了Comment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: print
import org.w3c.dom.Comment; //导入依赖的package包/类
protected void print(Node node, Map namespaces, boolean endWithComma) {
switch (node.getNodeType()) {
case Node.ELEMENT_NODE :
printElement((Element) node, namespaces, endWithComma);
break;
case Node.PROCESSING_INSTRUCTION_NODE :
printPI((ProcessingInstruction) node, endWithComma);
break;
case Node.TEXT_NODE :
printText((Text) node, endWithComma);
break;
case Node.COMMENT_NODE :
printComment((Comment) node, endWithComma);
break;
}
}
示例2: addStatisticsAsText
import org.w3c.dom.Comment; //导入依赖的package包/类
protected Object addStatisticsAsText(String stats, Object result) throws UnsupportedEncodingException{
if (result != null) {
if (stats == null) stats = context.statistics.printStatistics();
if (result instanceof Document) {
Document document = (Document) result;
Comment comment = document.createComment("\n" + stats);
document.appendChild(comment);
}
else if (result instanceof byte[]) {
String encodingCharSet = "UTF-8";
if (context.requestedObject != null)
encodingCharSet = context.requestedObject.getEncodingCharSet();
String sResult = new String((byte[]) result, encodingCharSet);
sResult += "<!--\n" + stats + "\n-->";
result = sResult.getBytes(encodingCharSet);
}
}
return result;
}
示例3: nextElement
import org.w3c.dom.Comment; //导入依赖的package包/类
public static Element nextElement(Iterator iter) {
while (iter.hasNext()) {
Node n = (Node) iter.next();
if (n instanceof Text) {
Text t = (Text) n;
if (t.getData().trim().length() == 0)
continue;
fail("parsing.nonWhitespaceTextFound", t.getData().trim());
}
if (n instanceof Comment)
continue;
if (!(n instanceof Element))
fail("parsing.elementExpected");
return (Element) n;
}
return null;
}
示例4: getText
import org.w3c.dom.Comment; //导入依赖的package包/类
/**
* Extract the textual content from a Node.
* This is rather like the XPath value of a Node.
* @param node The node to extract the text from
* @return The textual value of the node
*/
public static String getText(Node node)
{
StringBuffer reply = new StringBuffer();
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++)
{
Node child = children.item(i);
if ((child instanceof CharacterData && !(child instanceof Comment)) || child instanceof EntityReference)
{
reply.append(child.getNodeValue());
}
else if (child.getNodeType() == Node.ELEMENT_NODE)
{
reply.append(getText(child));
}
}
return reply.toString();
}
示例5: serializeComment
import org.w3c.dom.Comment; //导入依赖的package包/类
/**
* Serializes a Comment Node.
*
* @param node The Comment Node to serialize
*/
protected void serializeComment(Comment node) throws SAXException {
// comments=true
if ((fFeatures & COMMENTS) != 0) {
String data = node.getData();
// well-formed=true
if ((fFeatures & WELLFORMED) != 0) {
isCommentWellFormed(data);
}
if (fLexicalHandler != null) {
// apply the LSSerializer filter after the operations requested by the
// DOMConfiguration parameters have been applied
if (!applyFilter(node, NodeFilter.SHOW_COMMENT)) {
return;
}
fLexicalHandler.comment(data.toCharArray(), 0, data.length());
}
}
}
示例6: moveToChild
import org.w3c.dom.Comment; //导入依赖的package包/类
protected int moveToChild(final int currentChild) {
content = getCurrentElement().getChildNodes().item(currentChild);
if (content instanceof Text) {
return CHARACTERS;
} else if (content instanceof Element) {
return START_ELEMENT;
} else if (content instanceof CDATASection) {
return CDATA;
} else if (content instanceof Comment) {
return CHARACTERS;
} else if (content instanceof EntityReference) {
return ENTITY_REFERENCE;
}
throw new IllegalStateException();
}
示例7: stripComments
import org.w3c.dom.Comment; //导入依赖的package包/类
private static void stripComments(NodeList children) {
org.w3c.dom.Node child;
List<Comment> remove;
remove = new ArrayList<>();
for (int i = 0, max = children.getLength(); i < max; i++) {
child = children.item(i);
if (child instanceof Element) {
stripComments(child.getChildNodes());
} else if (child instanceof Comment) {
remove.add((Comment) child);
} else {
// nothing to do
}
}
for (Comment c : remove) {
c.getParentNode().removeChild(c);
}
}
示例8: parseNode
import org.w3c.dom.Comment; //导入依赖的package包/类
protected static XNode parseNode(Node domNode) {
if (domNode instanceof Element) {
return XElement.parse((Element) domNode);
}
if (domNode instanceof Text) {
return new XText(((Text) domNode).getTextContent());
}
if (domNode instanceof Comment) {
return new XComment(((Comment) domNode).getTextContent());
}
if (domNode instanceof ProcessingInstruction) {
return new XProcessingInstruction(((ProcessingInstruction) domNode).getTarget(), ((ProcessingInstruction) domNode).getData());
}
if (domNode instanceof DocumentType) {
return new XDocumentType(((DocumentType) domNode).getName(), ((DocumentType) domNode).getInternalSubset());
}
throw new UnsupportedOperationException("implement " + domNode);
}
示例9: visitNode
import org.w3c.dom.Comment; //导入依赖的package包/类
static <R> R visitNode(Node node, NodeVisitor<R> visitor) {
switch (node.getNodeType()) {
case Node.ELEMENT_NODE: return visitor.visitElement((Element) node);
case Node.ATTRIBUTE_NODE: return visitor.visitAttr((Attr) node);
case Node.TEXT_NODE: return visitor.visitText((Text) node);
case Node.CDATA_SECTION_NODE: return visitor.visitCDATASection((CDATASection) node);
case Node.ENTITY_REFERENCE_NODE: return visitor.visitEntityReference((EntityReference) node);
case Node.ENTITY_NODE: return visitor.visitEntity((Entity) node);
case Node.PROCESSING_INSTRUCTION_NODE:
return visitor.visitProcessingInstruction((ProcessingInstruction) node);
case Node.COMMENT_NODE: return visitor.visitComment((Comment) node);
case Node.DOCUMENT_NODE: return visitor.visitDocument((Document) node);
case Node.DOCUMENT_TYPE_NODE: return visitor.visitDocumentType((DocumentType) node);
case Node.DOCUMENT_FRAGMENT_NODE:
return visitor.visitDocumentFragment((DocumentFragment) node);
case Node.NOTATION_NODE: return visitor.visitNotation((Notation) node);
default: throw new RuntimeException();
}
}
示例10: put
import org.w3c.dom.Comment; //导入依赖的package包/类
public Object put(Object key, Object value) {
if (key.toString().equalsIgnoreCase("XmlRoot")) {
return super.put(key, value);
} else if (key.toString().equalsIgnoreCase("XmlComment")) {
// Remove all comment nodes, and add 1 new one at the top
remove(key);
if (!((cfData) value).toString().trim().equals("")) {
try {
Comment c = ((Document) nodeData).createComment(((cfData) value).toString());
nodeData.insertBefore(c, nodeData.getFirstChild());
} catch (DOMException ex) {
// Nothing else we can do here
com.nary.Debug.printStackTrace(ex);
}
}
nodeData.normalize();
return null;
} else if (key.toString().equalsIgnoreCase("XMLDocType")) {
// Do nothing
return null;
} else {
return super.put(key, value);
}
}
示例11: serializeComment
import org.w3c.dom.Comment; //导入依赖的package包/类
/**
* Serializes a Comment Node.
*
* @param node The Comment Node to serialize
*/
protected void serializeComment(Comment node) throws SAXException {
// comments=true
if ((fFeatures & COMMENTS) != 0) {
String data = node.getData();
// well-formed=true
if ((fFeatures & WELLFORMED) != 0) {
isCommentWellFormed(data);
}
if (fLexicalHandler != null) {
// apply the LSSerializer filter after the operations requested by the
// DOMConfiguration parameters have been applied
if (!applyFilter(node, NodeFilter.SHOW_COMMENT)) {
return;
}
fLexicalHandler.comment(data.toCharArray(), 0, data.length());
}
}
}
示例12: testInvalidCharactersComment
import org.w3c.dom.Comment; //导入依赖的package包/类
public void testInvalidCharactersComment() throws Exception {
ErrorRecorder errorRecorder = new ErrorRecorder();
domConfiguration.setParameter("error-handler", errorRecorder);
domConfiguration.setParameter("namespaces", false);
Element root = document.createElement("foo");
document.appendChild(root);
Comment comment = document.createComment("");
root.appendChild(comment);
for (int c = 0; c <= Character.MAX_VALUE; c++) {
comment.setData(new String(new char[] { 'A', 'B', (char) c}));
document.normalizeDocument();
if (isValid((char) c)) {
assertEquals(Collections.<DOMError>emptyList(), errorRecorder.errors);
} else {
errorRecorder.assertAllErrors("For character " + c,
DOMError.SEVERITY_ERROR, "wf-invalid-character");
}
}
}
示例13: duplicate
import org.w3c.dom.Comment; //导入依赖的package包/类
public static Node duplicate(Node node, Document ownerDocument)
{
if (node instanceof Text)
return ownerDocument.createTextNode(node.getNodeValue());
if (node instanceof Comment)
return ownerDocument.createComment(node.getNodeValue());
Node newNode = ownerDocument.createElement(node.getNodeName());
NamedNodeMap attribs = node.getAttributes();
for (int i = 0; i < attribs.getLength(); i++)
{
Node attrib = attribs.item(i);
addAttribute(newNode, attrib.getNodeName(), attrib.getNodeValue());
}
for (Node n = node.getFirstChild(); n != null; n = n.getNextSibling())
{
Node newN = duplicate(n, ownerDocument);
newNode.appendChild(newN);
}
return newNode;
}
示例14: create
import org.w3c.dom.Comment; //导入依赖的package包/类
/**
* Creates a new XmlComment as child of given parent.
* @param parent The parent of the new XmlComment.
* @param contents optional initial contents, ignored if empty
* @return The created XmlElement.
* @throws VilException if element could not be created.
*/
public static XmlComment create(XmlElement parent, @ParameterMeta(name = "contents") String contents)
throws VilException {
XmlComment newElement = null;
if (null == parent) {
throw new VilException("Can not append child from NULL element!", VilException.ID_IS_NULL);
}
try {
Comment newNode = parent.getNode().getOwnerDocument().createComment(contents);
parent.getNode().appendChild(newNode); // notifies change
newElement = new XmlComment(parent, newNode);
parent.addChild(newElement); // notifies change
} catch (DOMException exc) {
throw new VilException("Invalid character, name or ID!", VilException.ID_INVALID);
}
if (null != contents && contents.length() > 0) {
newElement.setCdata(contents);
}
return newElement;
}
示例15: duplicate
import org.w3c.dom.Comment; //导入依赖的package包/类
public static Node duplicate(Node node, Document ownerDocument) {
if (node instanceof Text) {
return ownerDocument.createTextNode(node.getNodeValue());
}
if (node instanceof Comment) {
return ownerDocument.createComment(node.getNodeValue());
}
Node newNode = ownerDocument.createElement(node.getNodeName());
NamedNodeMap attribs = node.getAttributes();
for (int i = 0; i < attribs.getLength(); i++) {
Node attrib = attribs.item(i);
addAttribute(newNode, attrib.getNodeName(), attrib.getNodeValue());
}
for (Node n = node.getFirstChild(); n != null; n = n.getNextSibling()) {
Node newN = duplicate(n, ownerDocument);
newNode.appendChild(newN);
}
return newNode;
}