use of com.gargoylesoftware.htmlunit.html.DomCDataSection in project htmlunit by HtmlUnit.
the class XMLDOMNode method getChildNodes.
/**
* Returns a node list containing the child nodes.
* @return a node list containing the child nodes
*/
@JsxGetter
public XMLDOMNodeList getChildNodes() {
if (childNodes_ == null) {
final DomNode domNode = getDomNodeOrDie();
final boolean isXmlPage = domNode.getOwnerDocument() instanceof XmlPage;
final Boolean xmlSpaceDefault = isXMLSpaceDefault(domNode);
final boolean skipEmptyTextNode = isXmlPage && !Boolean.FALSE.equals(xmlSpaceDefault);
childNodes_ = new XMLDOMNodeList(domNode, false, "XMLDOMNode.childNodes") {
@Override
protected List<DomNode> computeElements() {
final List<DomNode> response = new ArrayList<>();
for (final DomNode child : domNode.getChildren()) {
// IE: XmlPage ignores all empty text nodes
if (skipEmptyTextNode && child instanceof DomText && !(child instanceof DomCDataSection) && StringUtils.isBlank(child.getNodeValue())) {
// and 'xml:space' is 'default'
continue;
}
response.add(child);
}
return response;
}
};
}
return childNodes_;
}
use of com.gargoylesoftware.htmlunit.html.DomCDataSection in project htmlunit by HtmlUnit.
the class XmlUtils method copy.
/**
* Copy all children from 'source' to 'dest', within the context of the specified page.
* @param page the page which the nodes belong to
* @param source the node to copy from
* @param dest the node to copy to
* @param handleXHTMLAsHTML if true elements from the XHTML namespace are handled as HTML elements instead of
* DOM elements
*/
private static void copy(final SgmlPage page, final Node source, final DomNode dest, final boolean handleXHTMLAsHTML, final Map<Integer, List<String>> attributesOrderMap) {
final NodeList nodeChildren = source.getChildNodes();
for (int i = 0; i < nodeChildren.getLength(); i++) {
final Node child = nodeChildren.item(i);
switch(child.getNodeType()) {
case Node.ELEMENT_NODE:
final DomNode childXml = createFrom(page, child, handleXHTMLAsHTML, attributesOrderMap);
dest.appendChild(childXml);
copy(page, child, childXml, handleXHTMLAsHTML, attributesOrderMap);
break;
case Node.TEXT_NODE:
dest.appendChild(new DomText(page, child.getNodeValue()));
break;
case Node.CDATA_SECTION_NODE:
dest.appendChild(new DomCDataSection(page, child.getNodeValue()));
break;
case Node.COMMENT_NODE:
dest.appendChild(new DomComment(page, child.getNodeValue()));
break;
case Node.PROCESSING_INSTRUCTION_NODE:
dest.appendChild(new DomProcessingInstruction(page, child.getNodeName(), child.getNodeValue()));
break;
default:
if (LOG.isWarnEnabled()) {
LOG.warn("NodeType " + child.getNodeType() + " (" + child.getNodeName() + ") is not yet supported.");
}
}
}
}
Aggregations