6 |
|
import java.util.ArrayList; |
7 |
|
|
8 |
|
import org.xml.sax.*; |
9 |
+ |
import org.xml.sax.helpers.*; |
10 |
|
import javax.xml.parsers.SAXParserFactory; |
11 |
|
import javax.xml.parsers.ParserConfigurationException; |
12 |
|
import javax.xml.parsers.SAXParser; |
17 |
|
* @author $Author$ |
18 |
|
* @version $Id$ |
19 |
|
*/ |
20 |
< |
public class XMLStringParser extends HandlerBase { |
20 |
> |
public class XMLStringParser extends DefaultHandler { |
21 |
|
|
22 |
|
//---FINAL ATTRIBUTES--- |
23 |
|
|
74 |
|
* "packet.attributes.machine_name" |
75 |
|
* within the XMLPacket. |
76 |
|
*/ |
77 |
< |
public void startElement (String name, AttributeList attrs) throws SAXException { |
77 |
> |
public void startElement (String name, Attributes attrs) throws SAXException { |
78 |
|
indentLevel++; |
79 |
|
tagList.add(name); |
80 |
|
if (attrs != null) { |
81 |
|
for (int i = 0; i < attrs.getLength (); i++) { |
82 |
< |
packet.addParam(getPath()+".attributes."+attrs.getName(i), attrs.getValue(i)); |
82 |
> |
packet.addParam(getPath()+".attributes."+attrs.getLocalName(i), attrs.getValue(i)); |
83 |
|
} |
84 |
|
} |
85 |
|
} |
102 |
|
*/ |
103 |
|
public void characters (char[] buf, int offset, int len) throws SAXException { |
104 |
|
String s = new String(buf, offset, len); |
105 |
< |
if (!s.trim().equals("")) { |
105 |
< |
packet.addParam(getPath(), s); |
106 |
< |
} |
105 |
> |
packet.addParam(getPath(), s); |
106 |
|
} |
107 |
|
|
108 |
|
/** |
145 |
|
|
146 |
|
//---ATTRIBUTES--- |
147 |
|
|
148 |
+ |
/** |
149 |
+ |
* To keep track of our identation level |
150 |
+ |
*/ |
151 |
|
private int indentLevel = 0; |
152 |
+ |
|
153 |
+ |
/** |
154 |
+ |
* An ArrayList of tags |
155 |
+ |
*/ |
156 |
|
private ArrayList tagList = new ArrayList(); |
157 |
+ |
|
158 |
+ |
/** |
159 |
+ |
* A reference to the XMLPacket we are making |
160 |
+ |
*/ |
161 |
|
private XMLPacket packet; |
162 |
|
|
163 |
|
/** |