本文整理匯總了Java中org.w3c.dom.Node.appendChild方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.appendChild方法的具體用法?Java Node.appendChild怎麽用?Java Node.appendChild使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.appendChild方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writePrimitiveAttribute
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Writes the given value as an attribute of the given node.
*/
protected void writePrimitiveAttribute(mxCodec enc, Object obj,
String attr, Object value, Node node)
{
if (attr == null || obj instanceof Map)
{
Node child = enc.document.createElement("add");
if (attr != null)
{
mxCodec.setAttribute(child, "as", attr);
}
mxCodec.setAttribute(child, "value", value);
node.appendChild(child);
}
else
{
mxCodec.setAttribute(node, attr, value);
}
}
示例2: marshal
import org.w3c.dom.Node; //導入方法依賴的package包/類
public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
throws MarshalException
{
Document ownerDoc = DOMUtils.getOwnerDocument(parent);
Element isElem = DOMUtils.createElement(ownerDoc, "X509IssuerSerial",
XMLSignature.XMLNS, dsPrefix);
Element inElem = DOMUtils.createElement(ownerDoc, "X509IssuerName",
XMLSignature.XMLNS, dsPrefix);
Element snElem = DOMUtils.createElement(ownerDoc, "X509SerialNumber",
XMLSignature.XMLNS, dsPrefix);
inElem.appendChild(ownerDoc.createTextNode(issuerName));
snElem.appendChild(ownerDoc.createTextNode(serialNumber.toString()));
isElem.appendChild(inElem);
isElem.appendChild(snElem);
parent.appendChild(isElem);
}
示例3: migrateBillingResultXml
import org.w3c.dom.Node; //導入方法依賴的package包/類
protected String migrateBillingResultXml(String billingXml)
throws ParserConfigurationException, SAXException, IOException,
TransformerException, XPathExpressionException {
Document document = XMLConverter.convertToDocument(billingXml, false);
NodeList nodeList = XMLConverter.getNodeListByXPath(document,
XPATH_GATHEREDEVENTS);
for (int i = 0; i < nodeList.getLength(); i++) {
Node gatheredEvents = nodeList.item(i);
if (!istotalEventCostsAlreadyPresent(gatheredEvents)
&& gatheredEvents.getChildNodes().getLength() > 0) {
Element totalCosts = createNodeTotalEventCosts(gatheredEvents);
gatheredEvents.appendChild(totalCosts);
}
}
return XMLConverter.convertToString(document, false);
}
示例4: appendChildren
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Appends the child nodes of another propbag into the node located by
* szNodeName
*
* @param szNodeName The path to insert into
* @param xml The propbag that we want the children of
*/
public void appendChildren(final String szNodeName, final PropBagEx xml)
{
checkNotAttribute(szNodeName);
ensureRoot();
xml.ensureRoot();
Node oNode = getNodeHelper(szNodeName, false, false);
if( oNode == null )
{
createNode(szNodeName, BLANK);
oNode = getNodeHelper(szNodeName, false, false);
}
final Document doc = oNode.getOwnerDocument();
Node child = xml.m_elRoot.getFirstChild();
while( child != null )
{
oNode.appendChild(importNode(doc, child, true));
child = child.getNextSibling();
}
// we might have pushed two text nodes together, normalise it
oNode.normalize();
}
示例5: marshal
import org.w3c.dom.Node; //導入方法依賴的package包/類
public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
throws MarshalException
{
Document ownerDoc = DOMUtils.getOwnerDocument(parent);
// prepend namespace prefix, if necessary
Element knElem = DOMUtils.createElement(ownerDoc, "KeyName",
XMLSignature.XMLNS, dsPrefix);
knElem.appendChild(ownerDoc.createTextNode(name));
parent.appendChild(knElem);
}
示例6: startElement
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Adds a new child {@link org.w3c.dom.Element Element} to the current
* node.
*
* @param namespaceURI the namespace URI
* @param localName the local name
* @param qName the qualified (prefixed) name
* @param atts the list of attributes
* @throws SAXException if the DOM implementation throws an exception
*/
@Override
public void startElement(String namespaceURI, String localName,
String qName, Attributes atts)
throws SAXException {
try {
Node previousTop = top;
if ((localName == null) || (localName.length() == 0)) {
top = doc.createElement(qName);
} else {
top = doc.createElementNS(namespaceURI, localName);
}
for (int i = 0; i < atts.getLength(); i++) {
Attr attr = null;
if ((atts.getLocalName(i) == null) ||
(atts.getLocalName(i).length() == 0)) {
attr = doc.createAttribute(atts.getQName(i));
attr.setNodeValue(atts.getValue(i));
((Element)top).setAttributeNode(attr);
} else {
attr = doc.createAttributeNS(atts.getURI(i),
atts.getLocalName(i));
attr.setNodeValue(atts.getValue(i));
((Element)top).setAttributeNodeNS(attr);
}
}
previousTop.appendChild(top);
depth++;
} catch (DOMException e) {
throw new SAXException(e.getMessage(), e);
}
}
示例7: marshalSKI
import org.w3c.dom.Node; //導入方法依賴的package包/類
private void marshalSKI(byte[] skid, Node parent, Document doc,
String dsPrefix)
{
Element skidElem = DOMUtils.createElement(doc, "X509SKI",
XMLSignature.XMLNS, dsPrefix);
skidElem.appendChild(doc.createTextNode(Base64.encode(skid)));
parent.appendChild(skidElem);
}
示例8: marshal
import org.w3c.dom.Node; //導入方法依賴的package包/類
public void marshal(Node parent, String dsPrefix,
DOMCryptoContext context)
throws MarshalException
{
// create SignatureValue element
sigValueElem = DOMUtils.createElement(ownerDoc, "SignatureValue",
XMLSignature.XMLNS, dsPrefix);
if (valueBase64 != null) {
sigValueElem.appendChild(ownerDoc.createTextNode(valueBase64));
}
// append Id attribute, if specified
DOMUtils.setAttributeID(sigValueElem, "Id", id);
parent.appendChild(sigValueElem);
}
示例9: makeText
import org.w3c.dom.Node; //導入方法依賴的package包/類
private void makeText(Node parent, int pos) {
if (pos <= this.pos) {
return;
}
Text text = document.createTextNode(contents.substring(this.pos, pos));
parent.appendChild(text);
this.pos = pos;
}
示例10: marshalCert
import org.w3c.dom.Node; //導入方法依賴的package包/類
private void marshalCert(X509Certificate cert, Node parent, Document doc,
String dsPrefix)
throws MarshalException
{
Element certElem = DOMUtils.createElement(doc, "X509Certificate",
XMLSignature.XMLNS, dsPrefix);
try {
certElem.appendChild(doc.createTextNode
(Base64.encode(cert.getEncoded())));
} catch (CertificateEncodingException e) {
throw new MarshalException("Error encoding X509Certificate", e);
}
parent.appendChild(certElem);
}
示例11: marshal
import org.w3c.dom.Node; //導入方法依賴的package包/類
public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
throws MarshalException
{
Document ownerDoc = DOMUtils.getOwnerDocument(parent);
Element rmElem = DOMUtils.createElement(ownerDoc, "RetrievalMethod",
XMLSignature.XMLNS, dsPrefix);
// add URI and Type attributes
DOMUtils.setAttribute(rmElem, "URI", uri);
DOMUtils.setAttribute(rmElem, "Type", type);
// add Transforms elements
if (!transforms.isEmpty()) {
Element transformsElem = DOMUtils.createElement(ownerDoc,
"Transforms",
XMLSignature.XMLNS,
dsPrefix);
rmElem.appendChild(transformsElem);
for (Transform transform : transforms) {
((DOMTransform)transform).marshal(transformsElem,
dsPrefix, context);
}
}
parent.appendChild(rmElem);
// save here node
here = rmElem.getAttributeNodeNS(null, "URI");
}
示例12: writeForkSection
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Writes a Fork output section <br>
* Author: Bertoli Marco
*
* @param doc
* document root
* @param node
* node where created section should be appended
* @param model
* data structure
* @param stationKey
* search's key for fork
*/
private static void writeForkSection(Document doc, Node node,
CommonModel model, Object stationKey) {
Element fork = doc.createElement(XML_E_STATION_SECTION);
fork.setAttribute(XML_A_STATION_SECTION_CLASSNAME, CLASSNAME_FORK);
node.appendChild(fork);
// Creates jobsPerLink parameter
XMLParameter jobsPerLink = new XMLParameter("jobsPerLink", model
.getStationNumberOfServers(stationKey).getClass().getName(),
null, model.getStationNumberOfServers(stationKey).toString(),
false);
// Creates block parameter
XMLParameter block = new XMLParameter("block", model
.getForkBlock(stationKey).getClass().getName(), null, model
.getForkBlock(stationKey).toString(), false);
// ...and adds them as fork's children
XMLParameter isSim = new XMLParameter("isSimplifiedFork", model
.getIsSimplifiedFork(stationKey).getClass().getName(), null,
model.getIsSimplifiedFork(stationKey).toString(), false);
jobsPerLink.appendParameterElement(doc, fork);
block.appendParameterElement(doc, fork);
isSim.appendParameterElement(doc, fork);
Vector<Object> classes = model.getClassKeys();
XMLParameter[] forkStrats = new XMLParameter[classes.size()];
Object currentClass;
for (int i = 0; i < forkStrats.length; i++) {
currentClass = classes.get(i);
forkStrats[i] = ForkStrategyWriter
.getForkStrategyParameter((ForkStrategy) model
.getForkStrategy(stationKey, currentClass),
model, currentClass, stationKey);
}
XMLParameter globalFork = new XMLParameter("ForkStrategy",
strategiesClasspathBase + "ForkStrategy", null, forkStrats,
false);
globalFork.appendParameterElement(doc, fork);
}
示例13: updateField
import org.w3c.dom.Node; //導入方法依賴的package包/類
@Override
public void updateField(ObjectName oname, String name, Object value) {
if (loading)
return;
// nothing by default
// log.info( "XXX UpdateField " + oname + " " + name + " " + value);
Node n = object2Node.get(oname);
if (n == null) {
log.info("Node not found " + oname);
return;
}
Node attNode = DomUtil.findChildWithAtt(n, "attribute", "name", name);
if (attNode == null) {
// found no existing attribute with this name
attNode = n.getOwnerDocument().createElement("attribute");
DomUtil.setAttribute(attNode, "name", name);
n.appendChild(attNode);
}
String oldValue = DomUtil.getAttribute(attNode, "value");
if (oldValue != null) {
// we'll convert all values to text content
DomUtil.removeAttribute(attNode, "value");
}
DomUtil.setText(attNode, value.toString());
// store();
}
示例14: processingInstruction
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* adds processing instruction node to DOM.
*/
public void processingInstruction(String target, String data) {
final Node last = (Node) _nodeStk.peek();
ProcessingInstruction pi = _document.createProcessingInstruction(target, data);
if (pi != null)
last.appendChild(pi);
}
示例15: createDocWithSequentTextNodes
import org.w3c.dom.Node; //導入方法依賴的package包/類
private Document createDocWithSequentTextNodes() throws Exception {
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = db.newDocument();
Node root = doc.createElement("root");
doc.appendChild(root);
root.appendChild(doc.createTextNode("\n"));
root.appendChild(doc.createTextNode("\n"));
root.appendChild(doc.createTextNode("\n"));
root.appendChild(doc.createTextNode(" "));
root.appendChild(doc.createTextNode("t"));
root.appendChild(doc.createTextNode("\n"));
root.appendChild(doc.createTextNode("t"));
root.appendChild(doc.createTextNode(" "));
Node child1 = doc.createElement("child1");
root.appendChild(child1);
child1.appendChild(doc.createTextNode(" "));
child1.appendChild(doc.createTextNode("\n"));
root.appendChild(doc.createTextNode("t"));
Node child2 = doc.createElement("child2");
root.appendChild(child2);
child2.appendChild(doc.createTextNode(" "));
root.appendChild(doc.createTextNode(" "));
Node child3 = doc.createElement("child3");
root.appendChild(child3);
child3.appendChild(doc.createTextNode(" "));
root.appendChild(doc.createTextNode(" "));
Node child4 = doc.createElement("child4");
root.appendChild(child4);
child4.appendChild(doc.createTextNode(" "));
root.appendChild(doc.createTextNode(" "));
Node child5 = doc.createElement("child5");
root.appendChild(child5);
child5.appendChild(doc.createTextNode("t"));
Node child51 = doc.createElement("child51");
child5.appendChild(child51);
child51.appendChild(doc.createTextNode(" "));
Node child511 = doc.createElement("child511");
child51.appendChild(child511);
child511.appendChild(doc.createTextNode("t"));
child51.appendChild(doc.createTextNode(" "));
child5.appendChild(doc.createTextNode("t"));
root.appendChild(doc.createTextNode(" "));
root.appendChild(doc.createComment(" test comment "));
root.appendChild(doc.createTextNode(" \n"));
root.appendChild(doc.createComment(" "));
root.appendChild(doc.createTextNode("\n"));
root.appendChild(doc.createProcessingInstruction("target1", "test"));
root.appendChild(doc.createTextNode(" "));
root.appendChild(doc.createTextNode(" "));
return doc;
}