


ajaypatelaj wrote:Can you please explain me.. i am beginnersongotho wrote:Hi,
U try to not connect with your MySQL database and you will know what is the right direction^^.
Alex




ajaypatelaj wrote:Hay plusminus.. thanks for this amazing tutorial....
can you please post importing data in sqlite from xml.... it will really help full all guys to build web service .. and all that type App .... Thanks... will eagerly wait for this tut ...






Menor wrote:The solution to local xml is:
xr.parse(new InputSource(getResources().getAssets().open("example.xml")));
Thanks

Any idea how to get values from an xml file like this:Using xml Syntax Highlighting
<current_conditions> <condition data="Clear"/> <temp_f data="61"/> <temp_c data="16"/> <humidity data="Humidity: 68%"/> <icon data="/ig/images/weather/sunny.gif"/> <wind_condition data="Wind: E at 13 mph"/> </current_conditions> --------------------------------------------------- <forecast_conditions> <day_of_week data="Tue"/> <low data="39"/> <high data="62"/> <icon data="/ig/images/weather/mostly_sunny.gif"/> <condition data="Mostly Sunny"/> </forecast_conditions> ----------------------------------------------------- <forecast_conditions> <day_of_week data="Wed"/> <low data="37"/> <high data="59"/> <icon data="/ig/images/weather/sunny.gif"/> <condition data="Clear"/> </forecast_conditions> Parsed in 0.004 seconds, using GeSHi 1.0.8.4
I want to get values from only the middle set of tags

amanni82 wrote:Menor wrote:The solution to local xml is:
xr.parse(new InputSource(getResources().getAssets().open("example.xml")));
Thanks
Any idea how to get values from an xml file like this:Using xml Syntax Highlighting
<current_conditions> <condition data="Clear"/> <temp_f data="61"/> <temp_c data="16"/> <humidity data="Humidity: 68%"/> <icon data="/ig/images/weather/sunny.gif"/> <wind_condition data="Wind: E at 13 mph"/> </current_conditions> --------------------------------------------------- <forecast_conditions> <day_of_week data="Tue"/> <low data="39"/> <high data="62"/> <icon data="/ig/images/weather/mostly_sunny.gif"/> <condition data="Mostly Sunny"/> </forecast_conditions> ----------------------------------------------------- <forecast_conditions> <day_of_week data="Wed"/> <low data="37"/> <high data="59"/> <icon data="/ig/images/weather/sunny.gif"/> <condition data="Clear"/> </forecast_conditions> Parsed in 0.004 seconds, using GeSHi 1.0.8.4
I want to get values from only the middle set of tags
if (localName.equals("condition")) {
String conditionData = atts.getValue("data"));
}


ancientgeek wrote:Hey Menor,
Would it be possible if you explain more? Or show an example code on getting the value between the tags based on their attribute values? I'm stuck at trying to extract the values based on the attribute value.
Thanks,
Joel
package mypackage;
import java.util.ArrayList;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import mypackage.FairBooth;
import mypackage.FairDataManager;
import mypackage.FairTopic;
public class FairListHandler extends DefaultHandler {
private boolean in_fairs = false;
private boolean in_fair = false;
private boolean in_name = false;
private boolean in_date = false;
private boolean in_active = false;
private boolean in_activeimage = false;
private boolean in_inactiveimage = false;
private boolean in_map = false;
private boolean in_info = false;
private boolean in_booths = false;
private boolean in_booth = false;
private boolean in_topics = false;
private boolean in_topic = false;
// here is put all fairs. when the first fair (on this example, we have just one fair on xml, but if there are many, this code also will work
// My data structure to put data
private ArrayList<FairDataManager> array = new ArrayList<FairDataManager>();
private FairDataManager parsedData = new FairDataManager();
private FairBooth fairBooth = new FairBooth();
private FairTopic fairTopic = new FairTopic();
public ArrayList getParsedData() {
return this.array;
}
@Override
public void startDocument() throws SAXException {
this.parsedData = new FairDataManager();
}
@Override
public void endDocument() throws SAXException {
// Nothing to do
}
@Override
public void startElement(String namespaceURI, String localName,
String qName, Attributes atts) throws SAXException {
if (localName.equals("fairs")) {
this.in_fairs = true;
} else if (localName.equals("fair")) {
this.in_fair = true;
} else if (localName.equals("name")) {
this.in_name = true;
} else if (localName.equals("date")) {
this.in_date = true;
} else if (localName.equals("active")) {
this.in_active = true;
} else if (localName.equals("active_image")) {
this.in_activeimage = true;
} else if (localName.equals("inactive_image")) {
this.in_inactiveimage = true;
} else if (localName.equals("map")) {
this.in_map = true;
} else if (localName.equals("info")) {
this.in_info = true;
} else if (localName.equals("booths")) {
this.in_booths = true;
} else if (localName.equals("booth")) {
this.in_booth = true;
fairBooth = new FairBooth();
// here i get the attributes values from <booth> tag
fairBooth.setBoothName(atts.getValue("name"));
fairBooth.setBoothPath(atts.getValue("target"));
} else if (localName.equals("topics")) {
this.in_topics = true;
} else if (localName.equals("topic")) {
this.in_topic = true;
fairTopic = new FairTopic();
fairTopic.setTopicName(atts.getValue("name"));
}
}
@Override
public void endElement(String namespaceURI, String localName, String qName)
throws SAXException {
if (localName.equals("fairs")) {
this.in_fairs = false;
} else if (localName.equals("fair")) {
this.in_fair = false;
//when the fair ends, add the fair on fair array
array.add(parsedData);
parsedData = new FairDataManager();
fairBooth = new FairBooth();
fairTopic = new FairTopic();
} else if (localName.equals("name")) {
this.in_name = false;
} else if (localName.equals("date")) {
this.in_date = false;
} else if (localName.equals("active")) {
this.in_active = false;
} else if (localName.equals("active_image")) {
this.in_activeimage = false;
} else if (localName.equals("inactive_image")) {
this.in_inactiveimage = false;
} else if (localName.equals("map")) {
this.in_map = false;
} else if (localName.equals("info")) {
this.in_info = false;
} else if (localName.equals("booths")) {
this.in_booths = false;
} else if (localName.equals("booth")) {
this.in_booth = false;
} else if (localName.equals("topics")) {
this.in_topics = false;
// when topics ends, add the booth on fair
parsedData.addBooth(fairBooth);
fairBooth = new FairBooth();
} else if (localName.equals("topic")) {
this.in_topic = false;
// when the topic ends, add topic on booth
fairBooth.addTopic(fairTopic);
fairTopic = new FairTopic();
}
}
@Override
public void characters(char ch[], int start, int length) {
if (this.in_name) {
// here i get the value between the tag <name>THIS_VALUE</name>
parsedData.setName(new String(ch, start, length));
}
if (this.in_date) {
// here i get the value between the tag <date>THIS_VALUE</date>
parsedData.setDate(new String(ch, start, length));
}
if (this.in_active) {
// here i get the value between the tag <active>THIS_VALUE</active>
String active = new String(ch, start, length);
if (active.equals("true")) {
parsedData.setActive(true);
} else {
parsedData.setActive(false);
}
}
if (this.in_activeimage) {
// here i get the value between the tag <active_image>THIS_VALUE</active_image>
parsedData.setActiveImage(new String(ch, start, length));
}
if (this.in_inactiveimage) {
// here i get the value between the tag <inactive_image>THIS_VALUE</inactive_image>
parsedData.setInactiveImage(new String(ch, start, length));
}
if (this.in_map) {
// here i get the value between the tag <map>THIS_VALUE</map>
parsedData.setMapUrl(new String(ch, start, length));
}
if (this.in_info) {
// here i get the value between the tag <info>THIS_VALUE</info>
parsedData.setInfoUrl(new String(ch, start, length));
}
if (this.in_topic) {
// here i get the value between the tag <topic>THIS_VALUE</topic>
fairTopic.setTopicPath(new String(ch, start, length));
}
}
}


Users browsing this forum: No registered users and 6 guests