Code example for Attributes

Methods: getIndex, getValue

0
		@Override 
		public void startElement(String namespaceURI, String localName,
				String qName, Attributes attrs) {
			Node n;
			if (qName.equals(NODE)) {
				if (attrs.getIndex(WORD) != -1)
					n = createWordNode(attrs);
				else 
					n = createStructureNode(attrs);
				 
				if (d_currentNode != null)
					d_currentNode.addChild(n);
				d_currentNode = n;
			} 
		} 
		 
		@Override 
		public void endElement(String namespaceURI, String localName,
				String qName) {
			if (qName.equals(NODE) && d_currentNode.getParent() != null)
				d_currentNode = d_currentNode.getParent();
		} 
 
		protected Node createStructureNode(Attributes attrs) {
			int id = Integer.parseInt(attrs.getValue(ID));
			int begin = Integer.parseInt(attrs.getValue(BEGIN));
			int end = Integer.parseInt(attrs.getValue(END));
			Map<String, String> attributes = new HashMap<String, String>();
			attributes.put(CAT, attrs.getValue(CAT));
			attributes.put(REL, attrs.getValue(REL));
 
			return new Node(d_currentNode, id, begin, end, attributes);
		} 
		 
		protected Node createWordNode(Attributes attrs) {
			int id = Integer.parseInt(attrs.getValue(ID));
			int begin = Integer.parseInt(attrs.getValue(BEGIN));
			int end = Integer.parseInt(attrs.getValue(END));
			Map<String, String> attributes = new HashMap<String, String>();
			attributes.put(REL, attrs.getValue(REL));
			attributes.put(POS, attrs.getValue(POS));
			attributes.put(ROOT, attrs.getValue(ROOT));
			attributes.put(WORD, attrs.getValue(WORD));
 
 
			return new Node(d_currentNode, id, begin, end, attributes);
		} 
	}