java setnodevalue_Java Node.getNodeValue方法代碼示例

本文整理匯總了Java中org.w3c.dom.Node.getNodeValue方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.getNodeValue方法的具體用法?Java Node.getNodeValue怎麽用?Java Node.getNodeValue使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.dom.Node的用法示例。

在下文中一共展示了Node.getNodeValue方法的20個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: parseInsertColumn

​點讚 3

import org.w3c.dom.Node; //導入方法依賴的package包/類

void parseInsertColumn(HashMap columns, Node columnNode, Database db, Table table) {

NamedNodeMap attrs = columnNode.getAttributes();

Node tableNameAttr = attrs.getNamedItem("table");

Node columnNameAttr = attrs.getNamedItem("name");

String tableName = tableNameAttr.getNodeValue();

String columnName = columnNameAttr.getNodeValue();

assert(tableName.equalsIgnoreCase(table.getTypeName()));

Column column = table.getColumns().getIgnoreCase(columnName);

AbstractExpression expr = null;

NodeList children = columnNode.getChildNodes();

for (int i = 0; i < children.getLength(); i++) {

Node node = children.item(i);

if (node.getNodeType() == Node.ELEMENT_NODE) {

expr = parseExpressionTree(node, db);

ExpressionUtil.assignLiteralConstantTypesRecursively(expr,

VoltType.get((byte)column.getType()));

ExpressionUtil.assignOutputValueTypesRecursively(expr);

}

}

columns.put(column, expr);

}

開發者ID:s-store,項目名稱:s-store,代碼行數:25,

示例2: parseTransformation

​點讚 3

import org.w3c.dom.Node; //導入方法依賴的package包/類

private static void parseTransformation(SvgTree avg, Node nNode) {

NamedNodeMap a = nNode.getAttributes();

int len = a.getLength();

for (int i = 0; i < len; i++) {

Node n = a.item(i);

String name = n.getNodeName();

String value = n.getNodeValue();

if (SVG_TRANSFORM.equals(name)) {

if (value.startsWith("matrix(")) {

value = value.substring("matrix(".length(), value.length() - 1);

String[] sp = value.split(" ");

for (int j = 0; j < sp.length; j++) {

avg.matrix[j] = Float.parseFloat(sp[j]);

}

}

} else if (name.equals("y")) {

Float.parseFloat(value);

} else if (name.equals("x")) {

Float.parseFloat(value);

}

}

}

開發者ID:RaysonYeungHK,項目名稱:Svg2AndroidXml,代碼行數:25,

示例3: getAttribute

​點讚 3

import org.w3c.dom.Node; //導入方法依賴的package包/類

private String getAttribute(Node node, String attributeName)

throws Exception {

try {

NamedNodeMap attributes = node.getAttributes();

for (int i = 0; i < attributes.getLength(); i++) {

Node attributeNode = attributes.item(i);

if (attributeNode.getNodeName().equals(attributeName)) {

return attributeNode.getNodeValue();

}

}

return null;

} catch (Exception e) {

log.error(e);

log.error(e.getStackTrace());

throw (e);

}

}

開發者ID:Esri,項目名稱:defense-solutions-proofs-of-concept,代碼行數:18,

示例4: mergeStandardTextNode

​點讚 3

import org.w3c.dom.Node; //導入方法依賴的package包/類

private void mergeStandardTextNode(Node node)

throws IIOInvalidTreeException {

// Convert to comments. For the moment ignore the encoding issue.

// Ignore keywords, language, and encoding (for the moment).

// If compression tag is present, use only entries with "none".

NodeList children = node.getChildNodes();

for (int i = 0; i < children.getLength(); i++) {

Node child = children.item(i);

NamedNodeMap attrs = child.getAttributes();

Node comp = attrs.getNamedItem("compression");

boolean copyIt = true;

if (comp != null) {

String compString = comp.getNodeValue();

if (!compString.equals("none")) {

copyIt = false;

}

}

if (copyIt) {

String value = attrs.getNamedItem("value").getNodeValue();

COMMarkerSegment com = new COMMarkerSegment(value);

insertCOMMarkerSegment(com);

}

}

}

開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,

示例5: getContent

​點讚 2

import org.w3c.dom.Node; //導入方法依賴的package包/類

/**

* Get the trimmed text content of a node or null if there is no text

*/

public static String getContent(Node n) {

if (n == null)

return null;

Node n1 = DomUtil.getChild(n, Node.TEXT_NODE);

if (n1 == null)

return null;

String s1 = n1.getNodeValue();

return s1.trim();

}

開發者ID:how2j,項目名稱:lazycat,代碼行數:15,

示例6: addToScope

​點讚 2

import org.w3c.dom.Node; //導入方法依賴的package包/類

@Override

protected void addToScope(Scriptable scope, NodeList nodeList) {

if (nodeList != null) {

String nodeValue = null;

if (nodeList.getLength() > 0) {

Node node = nodeList.item(0);

nodeValue = node.getNodeValue();

if (node instanceof Element)

nodeValue = ((Element) node).getTextContent();

}

scope.put(getVariableName(), scope, nodeValue);

}

}

開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:14,

示例7: getTextContent

​點讚 2

import org.w3c.dom.Node; //導入方法依賴的package包/類

protected static String getTextContent(Node node) {

Node child = node.getFirstChild();

if( null == child )

return null;

return child.getNodeValue();

}

開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:8,

示例8: parseMap

​點讚 2

import org.w3c.dom.Node; //導入方法依賴的package包/類

private static Request parseMap(Node root) {

Request request = new Request();

Node name = root.getAttributes().getNamedItem("name");

request.name = name != null ? name.getNodeValue() : null;

Node url = root.getAttributes().getNamedItem("url");

request.url = url != null ? url.getNodeValue() : null;

Node srs = root.getAttributes().getNamedItem("srs");

request.srs = srs != null ? srs.getNodeValue() : null;

Node wesn = root.getAttributes().getNamedItem("wesn");

if (wesn != null) {

String[] s = wesn.getNodeValue().split(",");

request.wesn = new double[4];

for (int i = 0; i < 4; i++)

request.wesn[i] = Double.parseDouble(s[i]);

}

List layers = getElements(root, "wms_layer");

Iterator iter = layers.iterator();

request.layers = new RequestLayer[layers.size()];

for (int i = 0; i < layers.size(); i++)

request.layers[i] = parseLayer(iter.next());

return request;

}

開發者ID:iedadata,項目名稱:geomapapp,代碼行數:30,

示例9: _ProcessNode

​點讚 2

import org.w3c.dom.Node; //導入方法依賴的package包/類

private static void _ProcessNode(Node n, int level) throws Exception {

n.getAttributes();

n.getChildNodes();

// At this point, for JVM 1.6 and Xerces <= 1.3.1,

// Test-XML.xml::mytest:Y's attribute is (already) bad.

switch (n.getNodeType()) {

case Node.TEXT_NODE:

String str = n.getNodeValue().trim();

/* ...Only print non-empty strings... */

if (str.length() > 0) {

String valStr = n.getNodeValue();

_Println(valStr, level);

}

break;

case Node.COMMENT_NODE:

break;

default: {

String nodeNameStr = n.getNodeName();

_Println(nodeNameStr + " (" + n.getClass() + "):", level);

/* ...Print children... */

_ProcessChildren(n, level);

/* ...Print optional node attributes... */

_PrintAttributes(n, level);

}

}

}

開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:37,

示例10: getBean

​點讚 2

import org.w3c.dom.Node; //導入方法依賴的package包/類

public static Object getBean(String path, int i) {

try {

//創建文檔對象

DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = dFactory.newDocumentBuilder();

Document doc;

doc = builder.parse(new File(ToolDirFile.getClassesPath(XMLUtil.class) + path));

//獲取包含類名的文本節點

NodeList nl = doc.getElementsByTagName("className");

Node classNode;

if (0 == i) {

classNode = nl.item(0).getFirstChild();

}

else {

classNode = nl.item(1).getFirstChild();

}

String cName = classNode.getNodeValue();

//通過類名生成實例對象並將其返回

Class c = Class.forName(cName);

Object obj = c.newInstance();

return obj;

}

catch(Exception e){

e.printStackTrace();

return null;

}

}

開發者ID:nellochen,項目名稱:springboot-start,代碼行數:31,

示例11: VersionInfo

​點讚 2

import org.w3c.dom.Node; //導入方法依賴的package包/類

public VersionInfo(Element element) {

logger.debug("Constructor - entry");

NodeList nodeList = element.getChildNodes();

for (int n = 0; n < nodeList.getLength(); n++) {

Node node = nodeList.item(n);

if (node.getNodeType() == Node.ELEMENT_NODE) {

Element childElement = (Element) node;

if ("VERSION".equals(childElement.getNodeName())) {

String name = childElement.getAttribute("NAME");

String revision = childElement.getAttribute("REVISION");

if ("Compatible index structure version".equals(name)) {

setIndexStructure(revision);

} else if ("SES API version".equals(name)) {

setApi(revision);

} else if ("SES build".equals(name)) {

setBuild(revision);

} else {

logger.trace("Unexpected version information: " + name + " (" + revision + ")");

}

} else {

logger.trace("Unrecognized child node: '" + childElement.getNodeName() + "'");

}

} else if ((node.getNodeType() == Node.TEXT_NODE) && (node.getNodeValue() != null) && (node.getNodeValue().trim().length() > 0)) {

logger.trace("Unexpected text node (" + this.getClass().getName() + "): '" + node.getNodeValue() + "'");

}

}

NamedNodeMap namedNodeMap = element.getAttributes();

if (namedNodeMap != null) {

for (int a = 0; a < namedNodeMap.getLength(); a++) {

Attr attributeNode = (Attr) namedNodeMap.item(a);

logger.trace("Unrecognized attribute: '" + attributeNode.getName() + "'");

}

}

logger.debug("Constructor - exit");

}

開發者ID:Smartlogic-Semaphore-Limited,項目名稱:Java-APIs,代碼行數:39,

示例12: getAttribute

​點讚 2

import org.w3c.dom.Node; //導入方法依賴的package包/類

protected static String getAttribute(Node node, String name,

String defaultValue, boolean required)

throws IIOInvalidTreeException {

Node attr = node.getAttributes().getNamedItem(name);

if (attr == null) {

if (!required) {

return defaultValue;

} else {

fatal(node, "Required attribute " + name + " not present!");

}

}

return attr.getNodeValue();

}

開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:14,

示例13: process

​點讚 2

import org.w3c.dom.Node; //導入方法依賴的package包/類

@Override

public void process(HyperlinkEnv env) {

String className = env.getValueString();

Node n = env.getDocumentContext().getDocRoot().getNode().getAttributes().

getNamedItem(HibernateMappingXmlConstants.PACKAGE_ATTRIB);//NOI18N

String pack = n == null ? null : n.getNodeValue();

if(pack!=null && pack.length()>0){

if(!className.contains(".")){

className = pack + "." +className;

}

}

HibernateEditorUtil.findAndOpenJavaClass(className, env.getDocument());

}

開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,

示例14: getContent

​點讚 2

import org.w3c.dom.Node; //導入方法依賴的package包/類

/** Get the trimed text content of a node or null if there is no text

*/

public static String getContent(Node n ) {

if( n==null ) return null;

Node n1=DomUtil.getChild(n, Node.TEXT_NODE);

if( n1==null ) return null;

String s1=n1.getNodeValue();

return s1.trim();

}

開發者ID:lamsfoundation,項目名稱:lams,代碼行數:12,

示例15: parseSignsNode

​點讚 2

import org.w3c.dom.Node; //導入方法依賴的package包/類

/** Analiza el nodo con el listado de firmas.

* @param signsNode Nodo con el listado de firmas.

* @return Listado con la información de cada operación de firma. */

private static List parseSignsNode(final Node signsNode) {

final NodeList childNodes = signsNode.getChildNodes();

final List signs = new ArrayList();

int idx = nextNodeElementIndex(childNodes, 0);

while (idx != -1) {

final Node currentNode = childNodes.item(idx);

String id = null;

final NamedNodeMap nnm = currentNode.getAttributes();

if (nnm != null) {

final Node tmpNode = nnm.getNamedItem("Id"); //$NON-NLS-1$

if (tmpNode != null) {

id = tmpNode.getNodeValue();

}

}

signs.add(

new TriSign(

parseParamsListNode(currentNode),

id

)

);

idx = nextNodeElementIndex(childNodes, idx + 1);

}

return signs;

}

開發者ID:MiFirma,項目名稱:mi-firma-android,代碼行數:33,

示例16: OMStructure

​點讚 2

import org.w3c.dom.Node; //導入方法依賴的package包/類

public OMStructure(Element element) {

logger.debug("Constructor - entry");

NodeList nodeList = element.getChildNodes();

for (int n = 0; n < nodeList.getLength(); n++) {

Node node = nodeList.item(n);

if (node.getNodeType() == Node.ELEMENT_NODE) {

Element childElement = (Element) node;

if ("TERM_CLASSES".equals(childElement.getNodeName())) {

setClassTypes(this.getList(childElement, "TERM_CLASS", new ClassTypeFactory()));

} else if ("TERM_FACETS".equals(childElement.getNodeName())) {

setFacets(this.getList(childElement, "FIELD", new FieldFactory()));

} else if ("TERM_ATTRIBUTES".equals(childElement.getNodeName())) {

setAttributes(this.getList(childElement, "TERM_ATTRIBUTE", new AttributeFactory()));

} else if ("TERM_NOTES".equals(childElement.getNodeName())) {

setNotes(this.getList(childElement, "TERM_NOTE", new NoteFactory()));

} else if ("TERM_METADATA".equals(childElement.getNodeName())) {

setChoices(this.getList(childElement, "METADATA_DEF", new ChoiceFactory()));

} else if ("EQUIVALENCE_RELATIONS".equals(childElement.getNodeName())) {

setEquivalenceRelations(this.getList(childElement, "RELATION_DEF", new RelationFactory()));

} else if ("HIERARCHICAL_RELATIONS".equals(childElement.getNodeName())) {

setHierarchicalRelations(this.getList(childElement, "RELATION_DEF", new RelationFactory()));

} else if ("ASSOCIATIVE_RELATIONS".equals(childElement.getNodeName())) {

setAssociativeRelations(this.getList(childElement, "RELATION_DEF", new RelationFactory()));

} else if ("USERS".equals(childElement.getNodeName())) {

setUsers(this.getList(childElement, "USER_DEF", new UserFactory()));

} else {

logger.trace("Unrecognized child node: '" + childElement.getNodeName() + "'");

}

} else if ((node.getNodeType() == Node.TEXT_NODE) && (node.getNodeValue() != null) && (node.getNodeValue().trim().length() > 0)) {

logger.trace("Unexpected text node (" + this.getClass().getName() + "): '" + node.getNodeValue() + "'");

}

}

NamedNodeMap namedNodeMap = element.getAttributes();

if (namedNodeMap != null) {

for (int a = 0; a < namedNodeMap.getLength(); a++) {

Attr attributeNode = (Attr) namedNodeMap.item(a);

logger.trace("Unrecognized attribute: '" + attributeNode.getName() + "'");

}

}

logger.debug("Constructor - exit");

}

開發者ID:Smartlogic-Semaphore-Limited,項目名稱:Java-APIs,代碼行數:44,

示例17: addNodeInTree

​點讚 2

import org.w3c.dom.Node; //導入方法依賴的package包/類

/**

* Adds a node in the visual tree. This method is used by the @see fillDomTree method

*

* @param parent the parent (Can be the tree or a parent TreeItem)

* @param nodethe node to be added

*/

public boolean addNodeInTree(Object parent, Node node, IProgressMonitor monitor) {

TreeItem tItem = (TreeItem) parent;

String[] values = new String[2];

tItem.setData(node);

// calc the node text according to the node type

switch (node.getNodeType()) {

case Node.ELEMENT_NODE :

int dec = 0;

if (node.hasAttributes()) {// add a fake first node for 'Attributes' item

tItem.setData("dec", new Integer(dec = 1));

}

Node[] childs = XMLUtils.toNodeArray(node.getChildNodes());

tItem.setData("childs", childs);

tItem.setItemCount(childs.length + dec);

values[0] = node.getNodeName();

values[1] = getTextValue(node);

tItem.setText(values);

tItem.setImage(imageNode);

break;

case Node.TEXT_NODE :

tItem.setImage(imageText);

tItem.setText(node.getNodeValue().trim());

break;

case Node.ATTRIBUTE_NODE:

tItem.setImage(imageAttrib);

String str = node.getNodeName() + "=\"" + node.getNodeValue() + "\"";

tItem.setText(new String[] {str, str});

break;

case Node.ENTITY_NODE:

tItem.setText("[Entity]");

break;

case Node.ENTITY_REFERENCE_NODE :

tItem.setText("[Entityref]");

break;

case Node.PROCESSING_INSTRUCTION_NODE :

tItem.setText("[Pi]");

break;

case Node.COMMENT_NODE :

tItem.setText("[Comment]");

break;

case Node.DOCUMENT_FRAGMENT_NODE :

tItem.setText("[Docfgmt]");

break;

case Node.DOCUMENT_TYPE_NODE :

tItem.setText("[Doctype]");

break;

case Node.NOTATION_NODE :

tItem.setText("[Notation]");

break;

default: break;

}

return true;

}

開發者ID:convertigo,項目名稱:convertigo-eclipse,代碼行數:63,

示例18: insertSourceMarker

​點讚 2

import org.w3c.dom.Node; //導入方法依賴的package包/類

private static int insertSourceMarker(@NonNull Node parent, @NonNull Node node,

@NonNull File file, boolean after) {

int insertCount = 0;

Document doc = parent.getNodeType() ==

Node.DOCUMENT_NODE ? (Document) parent : parent.getOwnerDocument();

String comment;

try {

comment = SdkUtils.createPathComment(file, true);

} catch (MalformedURLException e) {

return insertCount;

}

Node prev = node.getPreviousSibling();

String newline;

if (prev != null && prev.getNodeType() == Node.TEXT_NODE) {

// Duplicate indentation from previous line. Once we switch the merger

// over to using the XmlPrettyPrinter, we won't need this.

newline = prev.getNodeValue();

int index = newline.lastIndexOf('\n');

if (index != -1) {

newline = newline.substring(index);

}

} else {

newline = "\n";

}

if (after) {

node = node.getNextSibling();

}

parent.insertBefore(doc.createComment(comment), node);

insertCount++;

// Can't add text nodes at the document level in Xerces, even though

// it will happily parse these

if (parent.getNodeType() != Node.DOCUMENT_NODE) {

parent.insertBefore(doc.createTextNode(newline), node);

insertCount++;

}

return insertCount;

}

開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:44,

示例19: getNodeValue

​點讚 2

import org.w3c.dom.Node; //導入方法依賴的package包/類

protected String getNodeValue(Node node) {

if (node != null) {

int len;

int nodeType = node.getNodeType();

switch (nodeType) {

case Node.ELEMENT_NODE:

if (sequence.getProject().isStrictMode()) {

return XMLUtils.prettyPrintElement((Element)node, true, false);

}

else {

len = node.getChildNodes().getLength();

Node firstChild = node.getFirstChild();

if (firstChild != null) {

int firstChildType = firstChild.getNodeType();

switch (firstChildType) {

case Node.CDATA_SECTION_NODE:

case Node.TEXT_NODE:

return ((len<2) ? firstChild.getNodeValue():XMLUtils.getNormalizedText(node));

case Node.ELEMENT_NODE:

return XMLUtils.prettyPrintElement((Element)node, true, false);

default:

return null;

}

} else {

if (Engine.logBeans.isInfoEnabled())

Engine.logBeans.warn("Applied XPath on step '"+ this +"' returned node with null value ('"+node.getNodeName()+"')");

return null;

}

}

case Node.CDATA_SECTION_NODE:

case Node.TEXT_NODE:

len = node.getChildNodes().getLength();

return ((len<2) ? node.getNodeValue():XMLUtils.getNormalizedText(node));

case Node.ATTRIBUTE_NODE:

return node.getNodeValue();

default:

if (Engine.logBeans.isInfoEnabled())

Engine.logBeans.warn("Applied XPath on step '"+ this +"' is not supported");

return null;

}

}

return null;

}

開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:44,

示例20: obtenerNodoValor

​點讚 2

import org.w3c.dom.Node; //導入方法依賴的package包/類

private static String obtenerNodoValor(String strTag, Element eNodo) {

Node nValor = (Node) eNodo.getElementsByTagName(strTag).item(0).getFirstChild();

return nValor.getNodeValue();

}

開發者ID:mroodschild,項目名稱:froog,代碼行數:5,

注:本文中的org.w3c.dom.Node.getNodeValue方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要修改XML中CDATA区域中的某个节点,可以使用Java的DOM解析器和XPath表达式。 首先,使用DOM解析器将XML文件解析为DOM树。然后,使用XPath表达式选择要修改的节点。最后,使用DOM API修改该节点的值,并将DOM树写回到XML文件中。 以下是一个示例代码: ```java import java.io.File; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Document; import org.w3c.dom.Node; public class ModifyCDATANode { public static void main(String[] args) throws Exception { // Load XML file DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new File("input.xml")); // Select CDATA node using XPath XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); XPathExpression expr = xpath.compile("//myNode/text()"); Node node = (Node) expr.evaluate(doc, XPathConstants.NODE); // Modify CDATA value node.setNodeValue("new value"); // Write DOM tree back to XML file TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(new File("output.xml")); transformer.transform(source, result); } } ``` 在上面的示例中,我们选择了名为“myNode”的节点,并将其值修改为“new value”。最后,我们将修改后的DOM树写回到名为“output.xml”的文件中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值