use of org.w3c.dom.DocumentFragment in project jOOQ by jOOQ.
the class XMLasDOMBinding method fromString.
/**
* Create a new DOM element in an independent document
*/
public static Document fromString(String name) {
Document document = builder().newDocument();
DocumentFragment fragment = createContent(document, name);
if (fragment != null) {
document.appendChild(fragment);
} else {
document.appendChild(document.createElement(name));
}
return document;
}
use of org.w3c.dom.DocumentFragment in project robovm by robovm.
the class ImportNode method testImportNode8.
// Assumes validation.
// public void testImportNode7() throws Throwable {
// Document doc;
// Document aNewDoc;
// Element element;
// Node aNode;
// NamedNodeMap attributes;
// String name;
// Node attr;
// String lname;
// String namespaceURI = "http://www.nist.gov";
// String qualifiedName = "emp:employee";
// doc = (Document) load("staffNS", builder);
// aNewDoc = (Document) load("staff", builder);
// element = aNewDoc.createElementNS(namespaceURI, qualifiedName);
// aNode = doc.importNode(element, false);
// attributes = aNode.getAttributes();
// assertEquals("throw_Size", 1, attributes.getLength());
// name = aNode.getNodeName();
// assertEquals("nodeName", "emp:employee", name);
// attr = attributes.item(0);
// lname = attr.getLocalName();
// assertEquals("lname", "defaultAttr", lname);
// }
public void testImportNode8() throws Throwable {
Document doc;
Document aNewDoc;
DocumentFragment docFrag;
Node aNode;
boolean hasChild;
Document ownerDocument;
DocumentType docType;
String system;
doc = (Document) load("staffNS", builder);
aNewDoc = (Document) load("staffNS", builder);
docFrag = aNewDoc.createDocumentFragment();
aNode = doc.importNode(docFrag, false);
hasChild = aNode.hasChildNodes();
assertFalse("hasChild", hasChild);
ownerDocument = aNode.getOwnerDocument();
docType = ownerDocument.getDoctype();
system = docType.getSystemId();
assertURIEquals("system", null, null, null, "staffNS.dtd", null, null, null, null, system);
}
use of org.w3c.dom.DocumentFragment in project robovm by robovm.
the class NodeSetPrefix method testSetPrefix1.
/**
* Runs the test case.
*
* @throws Throwable
* Any uncaught exception causes test to fail
*/
public void testSetPrefix1() throws Throwable {
Document doc;
DocumentFragment docFragment;
Element element;
String elementTagName;
String elementNodeName;
doc = (Document) load("staff", builder);
docFragment = doc.createDocumentFragment();
element = doc.createElementNS("http://www.w3.org/DOM/Test", "emp:address");
docFragment.appendChild(element);
element.setPrefix("dmstc");
elementTagName = element.getTagName();
elementNodeName = element.getNodeName();
assertEquals("nodesetprefix01_tagname", "dmstc:address", elementTagName);
assertEquals("nodesetprefix01_nodeName", "dmstc:address", elementNodeName);
}
use of org.w3c.dom.DocumentFragment in project translationstudio8 by heartsome.
the class MessageParser method htmlToText.
/**
* 将 html 格式的文本过滤掉标签.
* @param html
* html 格式的字符串
* @return String
* 过滤掉 html 标签后的文本。如果 html 为空,返回空串""
*/
private String htmlToText(String html) {
if (html == null) {
return "";
}
DOMFragmentParser parser = new DOMFragmentParser();
CoreDocumentImpl codeDoc = new CoreDocumentImpl();
InputSource inSource = new InputSource(new ByteArrayInputStream(html.getBytes()));
inSource.setEncoding(textCharset);
DocumentFragment doc = codeDoc.createDocumentFragment();
try {
parser.parse(inSource, doc);
} catch (Exception e) {
return "";
}
textBuffer = new StringBuffer();
processNode(doc);
return textBuffer.toString();
}
use of org.w3c.dom.DocumentFragment in project XobotOS by xamarin.
the class InnerNodeImpl method insertChildAt.
/**
* Inserts {@code newChild} at {@code index}. If it is already child of
* another node, it is removed from there.
*/
Node insertChildAt(Node newChild, int index) throws DOMException {
if (newChild instanceof DocumentFragment) {
NodeList toAdd = newChild.getChildNodes();
for (int i = 0; i < toAdd.getLength(); i++) {
insertChildAt(toAdd.item(i), index + i);
}
return newChild;
}
LeafNodeImpl toInsert = (LeafNodeImpl) newChild;
if (toInsert.document != null && document != null && toInsert.document != document) {
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, null);
}
if (toInsert.isParentOf(this)) {
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, null);
}
if (toInsert.parent != null) {
int oldIndex = toInsert.index;
toInsert.parent.children.remove(oldIndex);
toInsert.parent.refreshIndices(oldIndex);
}
children.add(index, toInsert);
toInsert.parent = this;
refreshIndices(index);
return newChild;
}
Aggregations