1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| public class XmlContentHandler implements ContentHandler {
private Locator locator;
public void characters(char[] ch, int start, int length)
throws SAXException {
String s = new String(ch, start, length);
System.out.println("characters: " + s);
}
public void endDocument() throws SAXException {
System.out.println("...Parsing ends.");
}
public void endElement(String uri, String localName, String name)
throws SAXException {
// TODO Auto-generated method stub
}
public void endPrefixMapping(String prefix) throws SAXException {
System.out.println("Mapping ends for prefix " + prefix);
}
public void ignorableWhitespace(char[] ch, int start, int length)
throws SAXException {
String s = new String(ch, start, length);
System.out.println("ignorableWhitespace: [" + s + "]");
}
public void processingInstruction(String target, String data)
throws SAXException {
System.out.println("PI: Target:" + target + " and Data:" + data);
}
public void setDocumentLocator(Locator locator) {
System.out.println(" * setDocumentLocator() called");
this.locator = locator;
}
public void skippedEntity(String name) throws SAXException {
System.out.println("Skipping entity " + name);
}
public void startDocument() throws SAXException {
System.out.println("Parsing begins...");
}
public void startElement(String uri, String localName, String name,
Attributes atts) throws SAXException {
System.out.print("startElement: " + localName);
if (!uri.equals("")) {
System.out.println(" in namespace " + uri +
" (" + atts + ")");
} else {
System.out.println(" has no associated namespace");
}
for (int i=0; i<atts.getLength(); i++) {
System.out.println(" Attribute: " + atts.getLocalName(i) +
"=" + atts.getValue(i));
if (atts.getLocalName(i).equalsIgnoreCase("h-ansi")){
skippedEntity(uri);
System.out.println("this attribute is skipped");
}
}
}
public void startPrefixMapping(String prefix, String uri)
throws SAXException {
System.out.println("Mapping starts for prefix " + prefix
+ " mapped to URI " + uri);
}
} |
Partager