本文整理匯總了Java中org.w3c.dom.Node.setNodeValue方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.setNodeValue方法的具體用法?Java Node.setNodeValue怎麽用?Java Node.setNodeValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.setNodeValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: extractFeatures
import org.w3c.dom.Node; //導入方法依賴的package包/類
public static ArrayList<Node> extractFeatures(Node n, Document D) {
ArrayList<Node> attrs = new ArrayList<Node>();
String type = n.getAttributes().getNamedItem("type").getNodeValue();
NodeList features = n.getChildNodes();
for (int i = 0; i < n.getChildNodes().getLength(); i++) {
if (n.getChildNodes().item(i) instanceof Element) {
features = n.getChildNodes().item(i).getChildNodes();
}
}
for (int i = 0; i < features.getLength(); i++) {
Node feature = features.item(i);
if (feature instanceof Element) {
String name = feature.getAttributes().getNamedItem("name")
.getNodeValue();
String value = extractFeatureValue(feature);
Node attr = D.createAttribute(type + ":" + name);
attr.setNodeValue(value);
attrs.add(attr);
}
}
return attrs;
}
示例2: mergeChildNodes
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Merge child nodes
*
* @param node current node base
* @param childNode child node if exist
* @param foundBean child bean
* @param currentChild current child node
* @param patternChild current pattern child
* @param nodeMap node map
* @param document document
* @param patternBean pattern bean
* @param children list relevant childs current node base
*/
private static void mergeChildNodes(Node node, Node childNode, BaseBean foundBean,
Node currentChild, Node patternChild, Map nodeMap, Document document,
BaseBean patternBean, List children) {
Node foundChild = childNode;
if (foundChild == null) {
foundChild = takeEqualNode(children, patternChild);
}
if (foundChild != null) {
if (foundChild != currentChild) {
node.removeChild(foundChild);
node.insertBefore(foundChild, currentChild);
}
if (foundBean != null) {
mergeBeans(nodeMap, foundBean, patternBean);
} else if (isRelevantNode(foundChild) && foundChild.hasChildNodes()) {
mergeNode(nodeMap, foundChild, patternChild);
} else {
foundChild.setNodeValue(patternChild.getNodeValue());
}
} else {
Node child = document.importNode(patternChild, true);
node.insertBefore(child, currentChild);
}
}
示例3: setText
import org.w3c.dom.Node; //導入方法依賴的package包/類
/** Set or replace the text value
*/
public static void setText(Node node, String val) {
Node chld=DomUtil.getChild(node, Node.TEXT_NODE);
if( chld == null ) {
Node textN=node.getOwnerDocument().createTextNode(val);
node.appendChild(textN);
return;
}
// change the value
chld.setNodeValue(val);
}
示例4: renameManifestPackage
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Replaces package value with passed packageOriginal string
*
* @param file File for AndroidManifest.xml
* @param packageOriginal Package name to replace
* @throws AndrolibException
*/
public static void renameManifestPackage(File file, String packageOriginal) throws AndrolibException {
try {
Document doc = loadDocument(file);
// Get the manifest line
Node manifest = doc.getFirstChild();
// update package attribute
NamedNodeMap attr = manifest.getAttributes();
Node nodeAttr = attr.getNamedItem("package");
nodeAttr.setNodeValue(packageOriginal);
saveDocument(file, doc);
} catch (SAXException | ParserConfigurationException | IOException | TransformerException ignored) {
}
}
示例5: makeCdataReplacements
import org.w3c.dom.Node; //導入方法依賴的package包/類
private static void makeCdataReplacements(Element element) throws Exception {
try {
Node cdata = XMLUtils.findChildNode(element, Node.CDATA_SECTION_NODE);
if (cdata != null) {
String s = cdata.getNodeValue();
if (!s.equals("")) {
StringEx sx = new StringEx(s);
Enumeration<String> keys = nameReplacements.keys();
String key, value;
while (keys.hasMoreElements()) {
key = keys.nextElement();
value = nameReplacements.get(key);
sx.replaceAll(key, value);
}
s = sx.toString();
cdata.setNodeValue(s);
}
}
}
catch (Exception e) {
throw new Exception("Unable to make replacements",e);
}
}
示例6: fixingPublicAttrsInProviderAttributes
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Any @string reference in a <provider> value in AndroidManifest.xml will break on
* build, thus preventing the application from installing. This is from a bug/error
* in AOSP where public resources cannot be part of an authorities attribute within
* a <provider> tag.
*
* This finds any reference and replaces it with the literal value found in the
* res/values/strings.xml file.
*
* @param file File for AndroidManifest.xml
* @throws AndrolibException
*/
public static void fixingPublicAttrsInProviderAttributes(File file) throws AndrolibException {
if (file.exists()) {
try {
Document doc = loadDocument(file);
XPath xPath = XPathFactory.newInstance().newXPath();
XPathExpression expression = xPath.compile("/manifest/application/provider");
Object result = expression.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
NamedNodeMap attrs = node.getAttributes();
if (attrs != null) {
Node provider = attrs.getNamedItem("android:authorities");
if (provider != null) {
String reference = provider.getNodeValue();
String replacement = pullValueFromStrings(file.getParentFile(), reference);
if (replacement != null) {
provider.setNodeValue(replacement);
saveDocument(file, doc);
}
}
}
}
} catch (SAXException | ParserConfigurationException | IOException |
XPathExpressionException | TransformerException ignored) {
}
}
}
示例7: updateAttributeValue
import org.w3c.dom.Node; //導入方法依賴的package包/類
private void updateAttributeValue(Node node, String attName,
int decimalPlacesSetting) {
if (node.hasAttributes()
&& !"NumberOfOccurrence".equals(node.getNodeName())
&& !"ParameterValue".equals(node.getNodeName())) {
Node attribute = node.getAttributes().getNamedItem(attName);
if (attribute != null) {
String priceValue = attribute.getNodeValue();
if (priceValue != null && priceValue.length() > 0) {
attribute.setNodeValue(getConvertedPrice(priceValue,
decimalPlacesSetting));
}
}
}
}
示例8: setByPath
import org.w3c.dom.Node; //導入方法依賴的package包/類
public static void setByPath(Node doc, String path, String value) {
Node node = getNodeByPath(doc, path, true);
if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
node.setNodeValue(value);
} else if (node.hasChildNodes() && node.getFirstChild().getNodeType() == Node.TEXT_NODE) {
node.getFirstChild().setTextContent(value);
} else if (node.getNodeType() == Node.ELEMENT_NODE) {
node.setTextContent(value);
}
}
示例9: setValueForNode
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Retrieves the text value from a node's child text node.
*/
static void setValueForNode(Node node, String value)
{
if( node != null )
{
switch( node.getNodeType() )
{
case Node.ELEMENT_NODE: {
Node child = node.getFirstChild();
if( child == null )
{
Document doc = node.getOwnerDocument();
node.appendChild(doc.createTextNode(value));
}
else
{
child.setNodeValue(value);
}
break;
}
case Node.ATTRIBUTE_NODE: {
Attr attribute = (Attr) node;
attribute.getOwnerElement().setAttribute(attribute.getName(), value);
break;
}
default:
break;
}
}
}
示例10: setText
import org.w3c.dom.Node; //導入方法依賴的package包/類
/** Set or replace the text value
*/
public static void setText(Node node, String val) {
Node chld=DomUtil.getChild(node, Node.TEXT_NODE);
if( chld == null ) {
Node textN=node.getOwnerDocument().createTextNode(val);
node.appendChild(textN);
return;
}
// change the value
chld.setNodeValue(val);
}
示例11: setValue
import org.w3c.dom.Node; //導入方法依賴的package包/類
public void setValue(String value) {
Node valueNode = getValueNodeStrict();
if (valueNode != null) {
valueNode.setNodeValue(value);
} else {
try {
addTextNode(value);
} catch (SOAPException e) {
throw new RuntimeException(e.getMessage());
}
}
}
示例12: setText
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Set or replace the text value
*/
public static void setText(Node node, String val) {
Node chld = DomUtil.getChild(node, Node.TEXT_NODE);
if (chld == null) {
Node textN = node.getOwnerDocument().createTextNode(val);
node.appendChild(textN);
return;
}
// change the value
chld.setNodeValue(val);
}
示例13: setValue
import org.w3c.dom.Node; //導入方法依賴的package包/類
@Override
public void setValue(String value) {
Node valueNode = getValueNodeStrict();
if (valueNode != null) {
valueNode.setNodeValue(value);
} else {
try {
addTextNode(value);
} catch (SOAPException e) {
throw new RuntimeException(e.getMessage());
}
}
}
示例14: acceptNode
import org.w3c.dom.Node; //導入方法依賴的package包/類
@Override
public short acceptNode(Node n) {
String localname = n.getLocalName();
if (localname.equals("_test-04")) {
Node child = n.getFirstChild();
String text = child.getNodeValue();
if (text.equals("T%e!s#t$")) {
child.setNodeValue("T%E!S#T$");
}
}
return FILTER_ACCEPT;
}
示例15: setAttribute
import org.w3c.dom.Node; //導入方法依賴的package包/類
public static void setAttribute(Node node, String attName, String val) {
NamedNodeMap attributes=node.getAttributes();
Node attNode=node.getOwnerDocument().createAttribute(attName);
attNode.setNodeValue( val );
attributes.setNamedItem(attNode);
}