Note that there are some explanatory texts on larger screens.

plurals
  1. POSax parser with string xml + malformation error
    text
    copied!<p>I am trying read data from an xml string and set the respective tag element using setter getter method but my xml shows a malformation error in xml file. What am i doing wrong here is my code.</p> <p>in oncreate..</p> <pre><code> SAXHelper2 sh = null; try { sh = new SAXHelper2(newxml); } catch (MalformedURLException e) { e.printStackTrace(); } sh.parseContent(""); return null; } </code></pre> <p>}</p> <pre><code> /* * */ class SAXHelper2 { private String data; StringBuffer chars = new StringBuffer(); public SAXHelper2(String xmlstring) throws MalformedURLException { this.data = new String(xmlstring); } DefaultHandler handler = new DefaultHandler(); public RSSHandler parseContent(String parseContent) { RSSHandler df = new RSSHandler(); try { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); saxParser.parse(new InputSource(newxml), new RSSHandler()); } catch (Exception e) { e.printStackTrace(); } return df; } class RSSHandler extends DefaultHandler { private ComptePost currentPost = new ComptePost(); StringBuffer chars = new StringBuffer(); public void startElement(String uri, String localName, String qName, Attributes atts) { chars = new StringBuffer(); if (localName.equalsIgnoreCase("comptes")) { } } DefaultHandler handler = new DefaultHandler() { @Override public void endElement(String uri, String localName, String qName) throws SAXException { if (localName.equalsIgnoreCase("numCompte") &amp;&amp; currentPost.getNumComtpe() == null) { System.out.println("Post: "+currentPost.getNumComtpe()); Log.i("numCompte", currentPost.getNumComtpe()); currentPost.setNumComtpe(chars.toString()); } if (localName.equalsIgnoreCase("authCompte") &amp;&amp; currentPost.getAuthCompte() == null) { currentPost.setAuthCompte(chars.toString()); } if (localName.equalsIgnoreCase("typeCompte") &amp;&amp; currentPost.getTypeCompte() == null) { currentPost.setTypeCompte(chars.toString()); } if (localName.equalsIgnoreCase("libelleCompte") &amp;&amp; currentPost.getLibelleCompte()== null) { currentPost.setLibelleCompte(chars.toString()); } if (localName.equalsIgnoreCase("soldeCompte") &amp;&amp; currentPost.getSoldeCompte() == null) { currentPost.setSoldeCompte(chars.toString()); } if (localName.equalsIgnoreCase("deviseCompte") &amp;&amp; currentPost.getDeviseCompte() == null) { currentPost.setDeviseCompte(chars.toString()); } if (localName.equalsIgnoreCase("dateSolde") &amp;&amp; currentPost.getDateSolde()== null) { currentPost.setDateSolde(chars.toString()); } if (localName.equalsIgnoreCase("droitVirement") &amp;&amp; currentPost.getDroitVirement()== null) { currentPost.setDroitVirement(chars.toString()); } if (localName.equalsIgnoreCase("carteBancaire") &amp;&amp; currentPost.getCarteBancaire()== null) { currentPost.setCarteBancaire(chars.toString()); } if (localName.equalsIgnoreCase("debitMin") &amp;&amp; currentPost.getDebitMin()== null) { currentPost.setDebitMin(chars.toString()); } if (localName.equalsIgnoreCase("debitMax") &amp;&amp; currentPost.getDebitMax()== null) { currentPost.setDebitMax(chars.toString()); } if (localName.equalsIgnoreCase("creditMin") &amp;&amp; currentPost.getCreditMin()== null) { currentPost.setCreditMin(chars.toString()); } if (localName.equalsIgnoreCase("creditMax") &amp;&amp; currentPost.getCreditMax()== null) { currentPost.setCreditMax(chars.toString()); } if (localName.equalsIgnoreCase("echeanceMax") &amp;&amp; currentPost.getEcheanceMax()== null) { currentPost.setEcheanceMax(chars.toString()); } if (localName.equalsIgnoreCase("comptes")) { PostList.add(currentPost); currentPost = new ComptePost(); } } @Override public void characters(char ch[], int start, int length) { chars.append(new String(ch, start, length)); } }; } } </code></pre> <p>java.io.IOException: Couldn't open Caused by: java.net.MalformedURLException: Protocol not found: </p> <pre><code>04-05 15:24:52.699: W/System.err(4784): at org.apache.harmony.xml.ExpatParser.openUrl(ExpatParser.java:760) 04-05 15:24:52.703: W/System.err(4784): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:289) 04-05 15:24:52.707: W/System.err(4784): at javax.xml.parsers.SAXParser.parse(SAXParser.java:390) 04-05 15:24:52.707: W/System.err(4784): at .details.CompteDetails$SAXHelper2.parseContent(CompteDetails.java:222) 04-05 15:24:52.707: W/System.err(4784): at .details.CompteDetails$loadingTask.doInBackground(CompteDetails.java:193) 04-05 15:24:52.710: W/System.err(4784): at .details.CompteDetails$loadingTask.doInBackground(CompteDetails.java:1) 04-05 15:24:52.710: W/System.err(4784): at android.os.AsyncTask$2.call(AsyncTask.java:185) 04-05 15:24:52.710: W/System.err(4784): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 04-05 15:24:52.714: W/System.err(4784): at java.util.concurrent.FutureTask.run(FutureTask.java:138) 04-05 15:24:52.714: W/System.err(4784): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 04-05 15:24:52.714: W/System.err(4784): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 04-05 15:24:52.718: W/System.err(4784): at java.lang.Thread.run(Thread.java:1019) 04-05 15:24:52.718: W/System.err(4784): at java.net.URL.&lt;init&gt;(URL.java:273) 04-05 15:24:52.722: W/System.err(4784): at java.net.URL.&lt;init&gt;(URL.java:157) 04-05 15:24:52.722: W/System.err(4784): at org.apache.harmony.xml.ExpatParser.openUrl(ExpatParser.java:753) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload