public void characters(char[] ch, int start, int length) throws SAXException { if(isColor){ trainCarColor.append(ch,start,length); } }
public void endElement(String uri, String localName, String qName) throws SAXException { if(isColor){ System.out.println("The color of the " + trainCarType + " car is" + trainCarColor.toString()); } isColor = false; }
public void startPrefixMapping(String prefix, String uri) throws SAXException { System.out.println("Start of Prefix Mapping"); System.out.println("The prefix is " + prefix); System.out.println("The uri is " + uri); }
public void endPrefixMapping(String prefix) throws SAXException { System.out.println("End of Prefix Mapping"); System.out.println("The prefix is " + prefix); } }
The problem is why it give different result between Code 1 and Code 2 in read(String fileName) method.
When use code 1, the result is : Running train reader... Start of the train End of the train
When use code 2, the result is : Running train reader... Start of the train Start of Prefix Mapping The prefix is myPrefix The uri is http://example.com The color of the Engine car isBlack The color of the Baggage car isGreen The color of the Dining car isGreen and Yellow The color of the Passenger car isGreen and Yellow The color of the Pullman car isGreen and Yellow The color of the Caboose car isRed End of Prefix Mapping The prefix is myPrefix End of the train
In code 1, the localName is always blank. I try to change the below value in all combination- true-true, true-false,flase-flase, flase-true. spfactory.setValidating(true); spfactory.setNamespaceAware(true);