public void setTextContent(String textContent) throws DOMException { NodeList nodes = getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { removeChild((Node)nodes.item(i)); } if (textContent != null && textContent.length() > 0) { Node node = domNode.getOwnerDocument().createTextNode(textContent); appendChild(node); } }
public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild) throws DOMException { newChild = convertDOMNode(newChild); if (newChild instanceof DocumentFragment) { List<NodeImpl> list = convertDocumentFragment((DocumentFragment)newChild); for (NodeImpl node : list) { appendChild(node); } return newChild; } if ((this instanceof SOAPElementImpl) == false) throw new DOMException(DOMException.INVALID_ACCESS_ERR, "Cannot append child to this node: " + this); NodeImpl soapNode = (NodeImpl)newChild; soapNode.detachNode(); domNode.appendChild(soapNode.domNode); soapNode.soapParent = (SOAPElementImpl)this; soapChildren.add(soapNode); return newChild; }
public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild) throws DOMException { // DOM says that if refChild is null, an append is performed if (refChild == null) return appendChild(newChild); newChild = convertDOMNode(newChild); refChild = convertDOMNode(refChild); if (newChild instanceof DocumentFragment) { List<NodeImpl> list = convertDocumentFragment((DocumentFragment)newChild); for (NodeImpl node : list) { insertBefore(node, refChild); } return newChild; } int index = soapChildren.indexOf(refChild); if (index < 0) throw new IllegalArgumentException(BundleUtils.getMessage(bundle, "CANNOT_FIND_REFCHILD")); NodeImpl soapNewNode = (NodeImpl)newChild; soapNewNode.detachNode(); NodeImpl soapRefNode = (NodeImpl)refChild; domNode.insertBefore(soapNewNode.domNode, soapRefNode.domNode); soapChildren.add(index, soapNewNode); soapNewNode.soapParent = (SOAPElementImpl)this; return newChild; }
/** * If this is a Text node then this method will set its value, otherwise it sets the value of the immediate (Text) child of this node. * <p/> * The value of the immediate child of this node can be set only if, there is one child node and * that node is a Text node, or if there are no children in which case a child Text node will be created. * * @param value A value string * @throws IllegalStateException if the node is not a Text node and either has more than one child node or has a child node that is not a Text node. */ public void setValue(String value) { // The Text node should overwrite setValue if (this instanceof javax.xml.soap.Text) throw new WSException(BundleUtils.getMessage(bundle, "IS_NOT_TEXT")); org.w3c.dom.Node child = (org.w3c.dom.Node)getFirstChild(); if (child instanceof org.w3c.dom.Text) ((org.w3c.dom.Text)child).setNodeValue(value); if (child == null) { child = domNode.getOwnerDocument().createTextNode(value); appendChild(new TextImpl(child)); } }