Results 1 to 2 of 2
  1. #1
    radish is offline Member
    Join Date
    Aug 2013
    Posts
    16
    Rep Power
    0

    Default [SOLVED] Using xml short tags with SAXParser

    Hi,

    I've managed to get basic xml processing done using SAXParser, so I altered my xml to how I have it in my specification (using xml short tags), e.g.
    Java Code:
     
    <?xml version="1.0"?>
    <obj name="x" type="y" state="z" />
    <obj name="xx" type="yy" state="zz" />
    But now it throws the following (fatal) error:
    The markup in the document following the root element must be well-formed.
    Is there any way to make it handle short xml tags?

    I also can implement the catch blocks, the "fatalError" exception is caught before the program quits, is there a way to get it to keep calm and carry on?

    Here's my handler code:
    Java Code:
     
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(false);
    saxParser = factory.newSAXParser();
    
    handler = new DefaultHandler() {
    
    	public void startElement(String uri, String localName, String qName, Attributes attributes)
    		throws SAXException {
        	        	
    		//System.out.println(":: " + qName);
    		int length = attributes.getLength();
    		for (int i=0; i<length; i++) {
    			String name = attributes.getQName(i);
    			String value = attributes.getValue(i);
    			//System.out.println("\t" + name + " : " + value);
    		}
    		//do_handle(qName);
    	}
    
    	public void fatalError(SAXParseException e) throws SAXException {
    		System.out.println("XML: FATALERROR");
    	}
    };
    Last edited by radish; 08-17-2013 at 09:16 PM.

  2. #2
    radish is offline Member
    Join Date
    Aug 2013
    Posts
    16
    Rep Power
    0

    Default Re: Using xml short tags with SAXParser

    Oops, xml (well here) needs to only have a single root element!

    Short tags are handled too ;)

Similar Threads

  1. SAXParser - Use enconding from XML
    By utikawa in forum XML
    Replies: 6
    Last Post: 02-07-2013, 06:00 PM
  2. Eclipse / JPA and SaxParser - confused
    By alexandra12 in forum Eclipse
    Replies: 0
    Last Post: 08-05-2012, 02:10 AM
  3. XML Parsing using SAXParser
    By krishanu in forum New To Java
    Replies: 9
    Last Post: 06-16-2011, 09:28 AM
  4. Replies: 3
    Last Post: 02-20-2011, 12:15 PM
  5. Initializing SAXParser
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-14-2007, 06:33 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •