本文整理了Java中org.dom4j.Node
类的一些代码示例,展示了Node
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node
类的具体详情如下:
包路径:org.dom4j.Node
类名称:Node
[英]Node
defines the polymorphic behavior for all XML nodes in a dom4j tree. A node can be output as its XML format, can be detached from its position in a document and can have XPath expressions evaluated on itself. A node may optionally support the parent relationship and may be read only.
[中]Node
定义dom4j树中所有XML节点的多态行为。节点可以作为其XML格式输出,可以从文档中的位置分离,并且可以对自身计算XPath表达式。节点可以选择支持父关系,并且可以是只读的。
代码示例来源:origin: spring-projects/spring-framework
@Test
public void withoutItemsEnumBindTarget() throws Exception {
BeanWithEnum testBean = new BeanWithEnum();
testBean.setTestEnum(TestEnum.VALUE_2);
getPageContext().getRequest().setAttribute("testBean", testBean);
this.tag.setPath("testEnum");
int result = this.tag.doStartTag();
assertEquals(Tag.SKIP_BODY, result);
String output = "<div>" + getOutput() + "</div>";
SAXReader reader = new SAXReader();
Document document = reader.read(new StringReader(output));
Element rootElement = document.getRootElement();
assertEquals(2, rootElement.elements().size());
Node value1 = rootElement.selectSingleNode("//input[@value = 'VALUE_1']");
Node value2 = rootElement.selectSingleNode("//input[@value = 'VALUE_2']");
assertEquals("TestEnum: VALUE_1",
rootElement.selectSingleNode("//label[@for = '" + value1.valueOf("@id") + "']").getText());
assertEquals("TestEnum: VALUE_2",
rootElement.selectSingleNode("//label[@for = '" + value2.valueOf("@id") + "']").getText());
assertEquals(value2, rootElement.selectSingleNode("//input[@checked]"));
}
代码示例来源:origin: pentaho/pentaho-kettle
private void addLoopXPath( Node node, IProgressMonitor monitor ) {
Element ce = (Element) node;
monitor.worked( 1 );
// List child
for ( int j = 0; j < ce.nodeCount(); j++ ) {
if ( monitor.isCanceled() ) {
return;
}
Node cnode = ce.node( j );
if ( !Utils.isEmpty( cnode.getName() ) ) {
Element cce = (Element) cnode;
if ( !listpath.contains( cnode.getPath() ) ) {
nr++;
monitor.subTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.FetchNodes",
String.valueOf( nr ) ) );
monitor.subTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.AddingNode",
cnode.getPath() ) );
listpath.add( cnode.getPath() );
}
// let's get child nodes
if ( cce.nodeCount() > 1 ) {
addLoopXPath( cnode, monitor );
}
}
}
}
代码示例来源:origin: igniterealtime/Openfire
protected void writeNode(Node node) throws IOException {
int nodeType = node.getNodeType();
switch (nodeType) {
case Node.ELEMENT_NODE:
writeCDATA(node.getText());
break;
case Node.ENTITY_REFERENCE_NODE:
break;
case Node.COMMENT_NODE:
writeComment(node.getText());
break;
case Node.DOCUMENT_NODE:
代码示例来源:origin: igniterealtime/Openfire
private Map<String, String> readInitParams(Node configData) {
Map<String, String> paramMap = new HashMap<>();
List<Node> params = configData.selectNodes("init-params/init-param");
for (Node param : params) {
String paramName = param.selectSingleNode("param-name").getStringValue();
String paramValue = param.selectSingleNode("param-value").getStringValue();
paramMap.put(paramName, paramValue);
}
return paramMap;
}
代码示例来源:origin: jaxen/jaxen
public Object getParentNode(Object contextNode)
{
if ( contextNode instanceof Node )
{
Node node = (Node) contextNode;
Object answer = node.getParent();
if ( answer == null )
{
answer = node.getDocument();
if (answer == contextNode) {
return null;
}
}
return answer;
}
return null;
}
代码示例来源:origin: spotbugs/spotbugs
private static String getChildText(Node node, String childName) throws PluginException {
Node child = node.selectSingleNode(childName);
if (child == null) {
throw new PluginException("Could not find child \"" + childName + "\" for node");
}
return child.getText();
}
代码示例来源:origin: igniterealtime/Openfire
final SAXReader saxReader = new SAXReader();
saxReader.setEncoding( "UTF-8" );
final Document pluginXML = saxReader.read( pluginConfig.toFile() );
final String className = pluginXML.selectSingleNode( "/plugin/class" ).getText().trim();
final Plugin plugin = (Plugin) pluginLoader.loadClass( className ).newInstance();
final Element adminElement = (Element) pluginXML.selectSingleNode( "/plugin/adminconsole" );
if ( adminElement != null )
final Element appName = (Element) adminElement.selectSingleNode( "/plugin/adminconsole/global/appname" );
if ( appName != null )
appName.addAttribute( "plugin", canonicalName );
Element imageEl = (Element) adminElement.selectSingleNode( "/plugin/adminconsole/global/logo-image" );
if ( imageEl != null )
代码示例来源:origin: jenkinsci/jenkins
Object result;
try {
Document dom = new SAXReader().read(new StringReader(sw.toString()));
XPath xExclude = dom.createXPath(exclude);
xExclude.setFunctionContext(functionContext);
List<org.dom4j.Node> list = (List<org.dom4j.Node>)xExclude.selectNodes(dom);
for (org.dom4j.Node n : list) {
Element parent = n.getParent();
if(parent!=null)
parent.remove(n);
result = dom;
} else {
XPath comp = dom.createXPath(xpath);
comp.setFunctionContext(functionContext);
List list = comp.selectNodes(dom);
for (Object o : list) {
if (o instanceof String) {
root.addText(o.toString());
} else {
root.add(((org.dom4j.Node)o).detach());
代码示例来源:origin: stackoverflow.com
SAXReader reader = new SAXReader();
Document document = reader.read(file);
List<Node> nodes = document.selectNodes("/options/category/option");
for (Node node : nodes) {
System.out.println("caption: " + node.selectSingleNode("control/caption").getText());
System.out.println("value : " + node.selectSingleNode("value").getText());
}
代码示例来源:origin: spotbugs/spotbugs
List<Node> componentNodeList = XMLUtil.selectNodes(pluginDescriptor, "/FindbugsPlugin/PluginComponent");
for (Node componentNode : componentNodeList) {
@DottedClassName String componentKindname = componentNode.valueOf("@componentKind");
if (componentKindname == null) {
throw new PluginException("Missing @componentKind for " + plugin.getPluginId()
+ " loaded from " + loadedFrom);
@DottedClassName String componentClassname = componentNode.valueOf("@componentClass");
if (componentClassname == null) {
throw new PluginException("Missing @componentClassname for " + plugin.getPluginId()
+ " loaded from " + loadedFrom);
String componentId = componentNode.valueOf("@id");
if (componentId == null) {
throw new PluginException("Missing @id for " + plugin.getPluginId()
String propertiesLocation = componentNode.valueOf("@properties");
boolean disabled = Boolean.valueOf(componentNode.valueOf("@disabled"));
String key = node.valueOf("@key");
String value = node.getText();
properties.setProperty(key, value);
List<Node> findBugsMainList = XMLUtil.selectNodes(pluginDescriptor, "/FindbugsPlugin/FindBugsMain");
for (Node main : findBugsMainList) {
String className = main.valueOf("@class");
if (className == null) {
throw new PluginException("Missing @class for FindBugsMain in plugin" + plugin.getPluginId()
+ " loaded from " + loadedFrom);
代码示例来源:origin: dom4j/dom4j
public void testBug926713() throws Exception {
Document doc = getDocument("/xml/test/cdata.xml");
Element foo = doc.getRootElement();
Element bar = foo.element("bar");
List content = bar.content();
assertEquals(3, content.size());
assertEquals(Node.TEXT_NODE, ((Node) content.get(0)).getNodeType());
assertEquals(Node.CDATA_SECTION_NODE, ((Node) content.get(1))
.getNodeType());
assertEquals(Node.TEXT_NODE, ((Node) content.get(2)).getNodeType());
}
}
代码示例来源:origin: dom4j/dom4j
public void testSetText1() throws Exception {
String newURL = "newURL";
Node urlNode = document.selectSingleNode("//root/author[1]/url");
urlNode.setText(newURL);
assertEquals(newURL, urlNode.getText());
assertTrue(urlNode instanceof Element);
Element urlElement = (Element) urlNode;
assertEquals(0, urlElement.elements().size());
}
代码示例来源:origin: jboss.jboss-embeddable-ejb3/hibernate-all
protected static void replaceNode(Node container, Element value) {
if ( container!=value ) { //not really necessary, I guess...
Element parent = container.getParent();
container.detach();
value.setName( container.getName() );
value.detach();
parent.add(value);
}
}
代码示例来源:origin: com.github.becausetesting/commons
public void setNodeValue(String xpath, String value) {
Element rootElement = document.getRootElement();
String namespace = rootElement.getNamespaceURI();
if (namespace != null) {
DefaultXPath defaultXPath = new DefaultXPath(xpath);
Map<String, String> namespaces = new TreeMap<String, String>();
namespaces.put("ns", namespace);
defaultXPath.setNamespaceURIs(namespaces);
defaultXPath.selectSingleNode(document).setText(value);
} else {
rootElement.selectSingleNode(xpath).setText(value);
}
}
代码示例来源:origin: org.dom4j/dom4j
public static DefaultNamespaceContext create(Object node) {
Element element = null;
if (node instanceof Element) {
element = (Element) node;
} else if (node instanceof Document) {
Document doc = (Document) node;
element = doc.getRootElement();
} else if (node instanceof Node) {
element = ((Node) node).getParent();
}
if (element != null) {
return new DefaultNamespaceContext(element);
}
return null;
}
代码示例来源:origin: com.atlassian.bamboo.plugins.dotnet/atlassian-bamboo-plugin-dotnet
@NotNull
private static Map<String, Node> cacheUnitTestNodes(final Node document, final String namespacePrefix)
{
final Map<String, Node> cachedTestInfo = new HashMap<>();
final List<Element> cachedNodes = document.selectNodes("//" + namespacePrefix + "UnitTest");
for (final Element e : cachedNodes)
{
cachedTestInfo.put(e.attributeValue("id"), e);
}
return cachedTestInfo;
}
代码示例来源:origin: pentaho/pentaho-kettle
Element e = (Element) node;
List<Attribute> lista = e.attributes();
for ( int i = 0; i < lista.size(); i++ ) {
setAttributeField( lista.get( i ), monitor );
String nodename = node.getName();
String nodenametxt = cleanString( node.getPath() );
String valueNode = node.getText();
代码示例来源:origin: USPTO/PatentPublicData
public NameOrg getOrgName(Node node) {
Node orgNameN = node.selectSingleNode("organization-name");
NameOrg name = orgNameN != null ? new NameOrg(orgNameN.getText()) : null;
if (name != null) {
try {
name.validate();
} catch (InvalidDataException e) {
LOGGER.warn("Org Name Invalid: {}", node.getParent().asXML(), e);
}
}
return name;
}
代码示例来源:origin: USPTO/PatentPublicData
public Examiner getExaminer(Node examinerNode, ExaminerType type) {
if (examinerNode == null) {
return null;
}
Node dataNode = examinerNode.selectSingleNode("PARTY-US");
Name name = new NameNode(dataNode).read();
Node artUnitN = examinerNode.getParent().selectSingleNode("B748US");
String artUnit = artUnitN != null ? artUnitN.getText() : null;
Examiner examiner = new Examiner(name, artUnit, type);
return examiner;
}
代码示例来源:origin: spotbugs/spotbugs
private static String findMessageText(List<Document> messageCollectionList, String xpath, String missingMsg) {
for (Document document : messageCollectionList) {
Node node = document.selectSingleNode(xpath);
if (node != null) {
return node.getText().trim();
}
}
return missingMsg;
}
内容来源于网络,如有侵权,请联系作者删除!