[xmlparser]Code-Node

package com.xml; import java.util.ArrayList; import java.util.List; public class Node { public final static int NODE_UNKNOW=-1; public final static int NODE_XML=0; public final static int NODE_DOCTYPE=1; public final static int NODE_TAG=2; public final static int NODE_TEXT=3; public final static int NODE_REMARK=4; public final static int NODE_CDATA=5; private int type; private List childs=new ArrayList(); private AttributeList attributes=new AttributeList(); private String value; public Node() {} public void setType(int type) { this.type = type; } public void setValue(String value) { this.value = value; } public void addAttribute(Attribute att) { attributes.addAttribute(att); } public int getType() { return type; } public AttributeList getAttributes() { return attributes; } public String getValue() { return value; } public String toString(){ return "#"+type+" "+ value; } public String getAttributeValue(String name){ Attribute att; for(int i=0,n=attributes.size();i<n;i++){ att=attributes.getAttribute(i); if(name.equals(att.getName())){ return att.getValue(); } } return null; } public void addChild(Node node){ childs.add(node); } public Node getChild(int i){ return (Node)childs.get(i); } public void dump(int level){ StringBuffer sb=new StringBuffer(); // for(int i=0;i<level;i++){ // sb.append('/t'); // } sb.append("Level=").append(level).append(" [type=").append(type).append(']').append(value); if(attributes.size()>0){ sb.append("/n/t/tAttributes: ").append(attributes.getAttributeList()); } System.out.println(sb); for(int i=0,n=childs.size();i<n;i++){ getChild(i).dump(level+1); } } }

你可能感兴趣的:(xml,String,list,Class,import,attributes)