Hi, I am trying to parse a xml file that contains a dataset, which has the structure below. <NewDataSet> <Table> <UserID>20</UserID> <Logo> </Logo> <LastUpdated></LastUpdated> </Table> </NewDataSet>
I am using the code below to save the incoming "Logo's".. but the whole dataset is not being parsed. The start, length attributes of "End Element" are not right as far as I can tell. [syntax="java"]public class LogoHandler extends DefaultHandler{ // =========================================================== // Fields // =========================================================== private boolean in_NewDataSet = false; private boolean in_Table= false; private boolean in_UserID= false; private boolean in_LastUpdated=false; private boolean in_Logo=false; Context mContext; public LogoHandler(Context ctx) { super(); mContext = ctx; } private ParsedExampleDataSet myParsedExampleDataSet = new ParsedExampleDataSet(mContext); // =========================================================== // Getter & Setter // =========================================================== public ParsedExampleDataSet getParsedData() { return this.myParsedExampleDataSet; } // =========================================================== // Methods // =========================================================== @Override public void startDocument() throws SAXException { this.myParsedExampleDataSet = new ParsedExampleDataSet (mContext); } @Override public void endDocument() throws SAXException { // Nothing to do } /** Gets be called on opening tags like: * <tag> * Can provide attribute(s), when xml was like: * <tag attribute="attributeValue">*/ @Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { if (localName.equals("NewDataSet")) { this.in_NewDataSet = true; }else if (localName.equals("Table")) { this.in_Table = true; }else if (localName.equals("UserID")) { this.in_UserID = true; } else if(localName.equals("Logo")) { this.in_Logo= true; } else if(localName.equals("LastUpdated")) { this.in_LastUpdated= true; } } //else if (localName.equals("tagwithnumber")) { // } // Extract an Attribute // String attrValue = atts.getValue("thenumber"); // int i = Integer.parseInt(attrValue); // myParsedExampleDataSet.setExtractedInt(i); // } /** Gets be called on closing tags like: * </tag> */ @Override public void endElement(String namespaceURI, String localName, String qName) throws SAXException { if (localName.equals("NewDataSet")) { this.in_NewDataSet = false; }else if (localName.equals("Table")) { this.in_Table= false; }else if (localName.equals("UserID")) { this.in_UserID = false; } else if(localName.equals("Logo")) { this.in_Logo=false; } else if(localName.equals("LastUpdated")) { this.in_LastUpdated= false; } } /** Gets be called on the following structure: * <tag>characters</tag> */ @Override public void characters(char ch[], int start, int length) { if(this.in_UserID) { myParsedExampleDataSet.setUserID(new String(ch, start, length)); } if(this.in_Logo) { myParsedExampleDataSet.setLogo(new String(ch, start, length)); } } }[/syntax] ParsedExampleDataSet : [syntax="java"]public String getUserID () { return UserID ; } public void setUserID (String UserID ) { this.UserID = UserID ; } public String getLogo() { return Logo; } public void setLogo(String Logo) { this.Logo=Logo; // INSERTING INTO DATABASE } [/syntax] Can some one help me on this? Waiting for a reply. Thanks, Immanuel --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---