Note that there are some explanatory texts on larger screens.

plurals
  1. POSAX Parser identical tag overwriting value
    primarykey
    data
    text
    <p>I am using a SAX Parser for an android app I am working on and I am having a hard time trying to save the name tag of Project from being overwritten. The problem here is that my name tag within the project is getting overwritten by the name tag within license since the tags are identical. The rest is getting parsed beautifully. Also, this xml is being generated by passing a GET Request to an API, so I can't edit it. Is there a way to maybe omit the name tag within the license field or maybe try to get a sense of where I'm at inside the document which is a problem since SAX is even driven. Also, I realize that I could accomplish this pretty easily using DOM but I have come way too far now to switch to DOM. I've attached snippets of my XML Handling code and the xml file I am trying to parse. </p> <p>Thanks</p> <pre><code>@Override public void startElement (String namespaceURI, String localName, String qName, Attributes attributes) throws SAXException { buffer.setLength(0); if (localName.equalsIgnoreCase("result")) { results = new ArrayList &lt;Result&gt; (); } if (localName.equalsIgnoreCase("project")) { result = new Result (); } if (localName.equalsIgnoreCase("name")) { result.name = buffer.toString (); Log.v("PROJECT NAME: ", result.name); } } // end of startElement () @Override public void endDocument () throws SAXException {} @Override public void endElement (String namespaceURI, String localName, String qName) throws SAXException { if (localName.equalsIgnoreCase("project") || localName.equalsIgnoreCase("account")) { this.entries++; results.add(result); } else if (localName.equalsIgnoreCase("id")) { result.id = buffer.toString (); Log.v("Id: ", result.id); } else if (localName.equalsIgnoreCase("created_at")) { try { result.date_created = ResultHandlerProject.DATE_FORMAT.parse(buffer.toString()); } catch (ParseException e) { e.printStackTrace(); } } else if (localName.equalsIgnoreCase("updated_at")) { try { result.date_updated = ResultHandlerProject.DATE_FORMAT.parse(buffer.toString()); } catch (ParseException e) { e.printStackTrace(); } } else if (localName.equalsIgnoreCase("description")) { result.description = buffer.toString (); } else if (localName.equalsIgnoreCase("homepage_url")) { result.url_homepage = buffer.toString (); } else if (localName.equalsIgnoreCase("download_url")) { result.url_download = buffer.toString (); } else if (localName.equalsIgnoreCase("medium_logo_url")) { result.image_link = buffer.toString (); } else if (localName.equalsIgnoreCase("user_count")) { result.user_count = buffer.toString (); } else if (localName.equalsIgnoreCase("average_rating")) { result.rating = buffer.toString (); } else if (localName.equalsIgnoreCase("rating_count")) { result.rating_count = buffer.toString (); } else if (localName.equalsIgnoreCase("analysis_id")) { result.analysis_id = buffer.toString (); } else if (localName.equalsIgnoreCase("nice_name")) { result.license_full_name = buffer.toString (); Log.v("License Full Name: ", result.license_full_name); } } // end of endElement () </code></pre> <p>Sample XML File:</p> <pre><code>&lt;result&gt; &lt;project&gt; &lt;id&gt;6050&lt;/id&gt; &lt;name&gt;FirePHP&lt;/name&gt; &lt;created_at&gt;2007-06-16T04:03:13Z&lt;/created_at&gt; &lt;updated_at&gt;2012-07-01T15:05:23Z&lt;/updated_at&gt; &lt;description&gt; FirePHP &lt;homepage_url&gt;http://www.firephp.org/&lt;/homepage_url&gt; &lt;download_url&gt;http://www.firephp.org/&lt;/download_url&gt; &lt;url_name&gt;FirePHP&lt;/url_name&gt; &lt;medium_logo_url&gt; https://s3.amazonaws.com/cloud.ohloh.net/attachments/6638/FirePHP_Large_White_med.png &lt;/medium_logo_url&gt; &lt;small_logo_url&gt; https://s3.amazonaws.com/cloud.ohloh.net/attachments/6638/FirePHP_Large_White_small.png &lt;/small_logo_url&gt; &lt;user_count&gt;145&lt;/user_count&gt; &lt;average_rating&gt;4.11765&lt;/average_rating&gt; &lt;rating_count&gt;34&lt;/rating_count&gt; &lt;analysis_id&gt;8910317&lt;/analysis_id&gt; &lt;licenses&gt; &lt;license&gt; &lt;name&gt;bsd&lt;/name&gt; &lt;nice_name&gt;BSD Copyright&lt;/nice_name&gt; &lt;/license&gt; &lt;/licenses&gt; &lt;/project&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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