dom4j API讲解

Element是dom4j的一个核心元素.
其常用api如下:
1.add(Attribute attribute)
描述:Adds the given Attribute to this element.
      向元素中添加指定的属性
2.add(CDATA cdata)
描述:Adds the given CDATA to this element.
     向元素中添加指定的CDATA,(这样对于xml特殊字符也可以直接输出)
3.add(Entity entity)
描述:Adds the given Entity to this element.
向元素中添加指定的Entity
4.add(Namespace namespace)
  描述:Adds the given Namespace to this element.
   向元素中添加指定的命名空间
5.add(Text text)
   描述:Adds the given Text to this element.
       向指定的元素中添加文本
6.addAttribute(QName qName, String value)
   描述:Adds the attribute value of the given fully qualified name.
   为给定的Qname添加对应的属性值
7.addAttribute(String name, String value)
  描述:Adds the attribute value of the given local name.
  给元素添加一个属性,名称为name,值为value
8.public List elements()
  描述:Returns the elements contained in this element. If this element does not contain any elements then this method returns an empty list. The list is backed by the element such that changes to the list will be reflected in the element though the reverse is not the case.
     返回这个元素中包含的元素,如果这个元素没有包含任何元素,这个方法返回一个空的list,这个list是被这个元素所返回的,所以list的改变会反射到这个元素上,尽管相反的情况并非如此。
9. List elements(String name)
描述:Returns the elements contained in this element with the given local name and any namespace. 
  返回这个元素下于指定名称和命名空间相同的的元素们
10.String elementText(String name) 
11.attribute(String name)
描述:Returns the attribute with the given name
返回给定名称的属性
12.element(String name)
  描述:Returns the first element for the given local name and any namespace.
       返回该元素下与给定名称相同的第一个元素
13. String getText()
  描述:Returns the text value of this element without recursing through child elements.
  不递归子元素,返回该元素的文本值
 
     

猜你喜欢

转载自jameszhao1987.iteye.com/blog/1258456
今日推荐