Results 1 to 4 of 4
  1. #1
    alexandra12 is offline Member
    Join Date
    Jul 2011
    Posts
    34
    Rep Power
    0

    Default Empty element parsing issue

    Hello,

    I am trying to parse an xml document and I am getting parser errors. One of the elements is empty - and this is where I get the errors.

    Here is sample code

    ERROR
    Java Code:
    java.lang.NumberFormatException: empty String
    	at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1038)
    	at java.lang.Double.valueOf(Double.java:487)

    GETTER/SETTER
    Java Code:
    @Column(length=10)
    private Double num=0.0;
    
    public Double getNum() {
    		return this.num;
    	}
    
    public void setNum(Double num) {
    	
    		//this.num = num == null ? 0.0 : num;
    		this.num = num == null ? Double.NaN : num;
    	}
    
    }
    SAMPLE SCHEMA WHERE IT ERRORS
    Java Code:
    <object>
    <label>label</label>
    <num/> // it errors here
    <units>zero</units>
    </object>
    SETTING THE VALUE IN THE CLASS - SAXPARSER
    Java Code:
    if(qName.equalsIgnoreCase("num")){
    			
    			Tmp.setNum(Double.valueOf(String).doubleValue());
    Can anyone offer any advice ?
    Thanks in advance

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Empty element parsing issue

    You left of the part of the error message that shows where in your code the error happened.

    Can you make a small, complete program that compiles, executes and shows the problem?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    alexandra12 is offline Member
    Join Date
    Jul 2011
    Posts
    34
    Rep Power
    0

    Default Re: Empty element parsing issue

    Here is the error

    Java Code:
    label is B6 G151 Rel Lab 1 
    in end label
    in the start element
    in the end element
    begining the transaction
    get entity manger
    going to begin
    going to perist
    going to commit
    java.lang.NullPointerException
    	at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1035)
    	at java.lang.Double.valueOf(Double.java:487)
    	at com.ibm.north.northCommander.endElement(northCommander.java:154)
    	at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)in the end element
    begining the transaction
    get entity manger
    going to begin
    going to perist
    going to commit
    
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    	at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    	at com.ibm.north.northCommander.main(northCommander.java:313)
    in end object
    Here is the xml file with the detail

    Java Code:
    <object id="P32O3" type="num" status="ok" updated="2012-08-20T02:52:18">
    <label>B6 G32 SDF Rel Lab</label>
    <num>101.17</num>
    <units>KW</units>
    </object>
    <object id="P32O4" type="num" status="ok" updated="2012-05-28T15:55:36" logavailable="true">
    <label>B6 G151 Rel Lab 1 </label>
    <num/>
    object>
    <object id="P32O5" type="num" status="ok" updated="2012-08-20T02:52:19" logavailable="true">
    <label>B6 G39 Server A</label>
    <num>14590.47</num>
    <units>KW</units>
    </object>
    I am using JPA to persist the data into the database with an entity manager

    Java Code:
    public String createRawData(RawData RawData)
    			throws Exception {
    		System.out.println("begining the transaction");
    		EntityManager em = getEntityManager();
    		System.out.println("get entity manger");
    		try {
    			System.out.println("going to begin");
    			em.getTransaction().begin();
    			System.out.println("going to perist");
    			em.persist(northRawData);
    			System.out.println("going to commit");
    			em.getTransaction().commit();
    			
    			
    		} catch (Exception ex) {
    			try {
    				if (em.getTransaction().isActive()) {
    					em.getTransaction().rollback();
    				}
    			} catch (Exception e) {
    				ex.printStackTrace();
    				throw e;
    			}
    			throw ex;
    		} finally {
    			em.close();
    		}
    		return "";
    	}

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Empty element parsing issue

    Sorry, no way to compile and test with what was posted.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] Empty JTable issue(blank rows)
    By doru.chiulan in forum AWT / Swing
    Replies: 3
    Last Post: 08-10-2012, 09:06 AM
  2. error for empty element in sax parser
    By alexandra12 in forum XML
    Replies: 9
    Last Post: 08-01-2012, 01:59 AM
  3. SAX Parsing element containing html
    By ianstanton in forum XML
    Replies: 1
    Last Post: 04-20-2011, 09:21 AM
  4. Replies: 0
    Last Post: 02-24-2011, 04:37 PM
  5. XML Parsing, strange empty/duplicated Nodes
    By Singing Boyo in forum Advanced Java
    Replies: 0
    Last Post: 08-18-2009, 07:57 AM

Posting Permissions

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