[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4668: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3815)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4670: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3815)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4671: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3815)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4672: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3815)
AndroidGreece.gr - View topic - XML_Parser
View unanswered posts | View active topics It is currently 27 Apr 2024, 08:34



Reply to topic  [ 12 posts ]  Go to page 1, 2  Next
 XML_Parser 
Author Message

Joined: 24 Mar 2009, 22:18
Posts: 20
Post XML_Parser
Είμαι νέος στο Android και ετοιμάζω τα πρώτα μου project σε αυτό. Θα ήθελα όμως να ρωτήσω πως γίνεται το διάβασμα ενός XML αρχείου μέσω του parser. Μπορεί κάποιος να μου απαντήσει? Είναι σημαντικό.


24 Mar 2009, 22:36
Profile
Site Admin
User avatar

Joined: 24 May 2008, 23:50
Posts: 626
Location: Athens
Post Re: XML_Parser
υπάρχουν δυο δημοφιλείς και αγαπημένοι τρόποι για να κάνεις parse ενα xml αρχείο.

ο πρώτος γρηγορότερος και ευκολότερος είναι να χρησιμοποιήσεις την βιβλιοθήκη xtream στο οποίο δημιουργείς μια κλάση με αυτό που περιμένεις να λάβεις και αυτό σου μετατρέπει το xml σε αντικείμενα αυτής της κλάσης αλλά και το αντίστροφο. Μπορείς να δεις το port του xstream στο android εδώ: http://jars.de/java/android-xml-seriali ... th-xstream Documentation μπορείς να βρεις εδώ: http://xstream.codehaus.org/

Ο δεύτερος "native" τρόπος είναι να χρησιμοποιήσεις τον xml parser του android όπως μπορείς να δεις με ενα πολύ καλό παράδειγμα εδώ: http://www.anddev.org/parsing_xml_from_ ... -t353.html

Αφού σε ενδιαφέρει θα προσπαθήσω όσο πιο γρήγορα γίνεται να ετοιμάσω κάποιο tutorial.

Καλή τύχη!

_________________
Chief Software Engineer @ PinApps.com
Κωνσταντίνος Πολυχρόνης
Πρόσθεσε την εφαρμογή σου:


25 Mar 2009, 00:46
Profile WWW

Joined: 24 Mar 2009, 22:18
Posts: 20
Post Re: XML_Parser
Ψάχνω εδώ και μέρες στο Internet για άρθρα ή παραδείγματα για το πώς διαβάζουμε δεδομένα από tags από xml αρχείο και αυτά που διαβάζω από το αρχείο να τα εμφανίζω στην οθόνη του Android, αλλά δεν βρήκα τίποτα που να με ικανοποιεί. Μήπως έχεις κάτι εσύ για μένα? Ετοιμάζω ένα project πάνω σε αυτό και πρέπει να μάθω πώς γίνεται. Help quickly!!


04 Apr 2009, 21:32
Profile
Site Admin
User avatar

Joined: 24 May 2008, 23:50
Posts: 626
Location: Athens
Post Re: XML_Parser
βασικά αυτό το link http://www.anddev.org/parsing_xml_from_ ... -t353.html έχει *ακριβώς* αυτό που θέλεις να κάνεις!

που έχεις το πρόβλημα;

_________________
Chief Software Engineer @ PinApps.com
Κωνσταντίνος Πολυχρόνης
Πρόσθεσε την εφαρμογή σου:


05 Apr 2009, 17:50
Profile WWW

Joined: 24 Mar 2009, 22:18
Posts: 20
Post Re: XML_Parser
Έχω τρέξει το πρόγραμμα του παραπάνου site.
Το πρόβλημα είναι η εξής γραμμή:
URL url = new URL("http://www.anddev.org/images/tut/basic/parsingxml/example.xml");
Το xml αρχείο το έχω στο project μου, στο φάκελο layout,έχω το URL url να είναι το path του xml στο layout φάκελο και δεν δουλεύει. Τι να βάλω στο URL url ώστε να δουλεύει?


06 Apr 2009, 12:55
Profile
Site Admin
User avatar

Joined: 24 May 2008, 23:50
Posts: 626
Location: Athens
Post Re: XML_Parser
Μέσα στον φάκελο layout μπαίνουν τα αρχεία που περιέχουν τον σχεδιασμό του layout των activities.
Μήπως πρέπει να το βάλεις κάπου αλλού;

Δεν πρέπει να το ανοίξεις σαν url. Πρέπει να το ανοίξεις σαν αρχείο, να πάρεις το stream και να το περάσεις στο xr.parse(...)

Λεπτομέρειες για τα resources μπορείς να βρεις εδώ: http://developer.android.com/guide/topi ... urces.html

_________________
Chief Software Engineer @ PinApps.com
Κωνσταντίνος Πολυχρόνης
Πρόσθεσε την εφαρμογή σου:


06 Apr 2009, 14:23
Profile WWW

Joined: 24 Mar 2009, 22:18
Posts: 20
Post Re: XML_Parser
Θα σου περιγράψω την εφαρμογή που μου έχει ανατεθεί να αναπτύξω, που σημαίνει ότι θα χρειαστώ βοήθεια από εσένα. Πιστεύω πως θα είναι παιχνιδάκι για σένα. Η εκφώνηση είναι η εξής:
H εφαρμογή θα διαβάζει ένα xml αρχείο, στο οποίο υπάρχουν ερωτήσεις αξιολόγησης, με όλες τις πιθανές απαντήσεις. Όλες οι ερωτήσεις και οι πιθανές απαντήσεις θα εμφανίζονται στην οθόνη της πλατφόρμας "Android" και θα δίνεται η δυνατότητα στο χρήστη να επιλέγει μια απάντηση κάθε φορά από την αντίστοιχη ερώτηση και ακόμα η δυνατότητα να μεταβαίνει στην επόμενη οθόνη για την επόμενη ερώτηση ή στην προηγούμενη οθόνη για τυχόν αλλαγή της απάντησης. Μια ερώτηση με τις αντίστοιχες πιθανές απαντήσεις καταλαμβάνουν μια οθόνη. Όλες οι ερωτήσεις και οι πιθανές απαντήσεις τους θα εμφανίζονται και θα ελέγχονται από κουμπιά ελέγχου και στοιχεία ελέγχου(textview, check boxes και radio buttons).
Το xml αρχείο είναι το εξής:
<?xml version="1.0" encoding="UTF-8" ?>
- <DATA>
- <question1>Σου αρέσει η C++ ?
<numberOfOptions>2</numberOfOptions>
<Option1>NAI</Option1>
<Option2>OXI</Option2>
</question1>
- <Question2> Σου αρέσει η η Java ?
<numberOption>3</numberOption>
<Option1>καθόλου</Option1>
<Option2>λίγο</Option2>
<Option3>πολύ</Option3>
</Question2>
</DATA>


08 Apr 2009, 11:54
Profile

Joined: 24 Mar 2009, 22:18
Posts: 20
Post Re: XML_Parser
Πώς σου φαίνεται? Μπορύμε να την λύσουμε ?


08 Apr 2009, 11:57
Profile

Joined: 24 Mar 2009, 22:18
Posts: 20
Post Re: XML_Parser
Προσπαθώ να κάνω parse ένα xml αρχείο χρησιμοποιώντας SAX parser και αντί να χρησιμοποιήσω URL url όπως είπαμε παραπάνω, χρησιμοποιώ τον παρακάτω κώδικα για να κάνω parse το αρχείο:

InputSource in=new InputSource();

in.setCharacterStream(new StringReader("C:\\example.xml"));
xr.parse(in);

αλλά βγάζει στην οθόνη το παρακάτω μήνυμα:

line 1, column 2: not well formed
(invalid token)

Τι σημαίνει αυτό? Μπορεί να μου εξηγήσει κάποιος ? Τι μπορώ να γράψω άλλο για να γίνει το parse του αρχείου?


27 Apr 2009, 09:23
Profile
Site Admin
User avatar

Joined: 24 May 2008, 23:50
Posts: 626
Location: Athens
Post Re: XML_Parser
τώρα μάλιστα:)

λοιπόν, το πρόβλημα υποθέτω οτι βρίσκεται στην κωδικοποίηση του UTF κατα το οποίο μπαίνει στην αρχή ενας ειδικός χαρακτήρας.

για αυτό το λόγο θα πρέπει να κόψεις τους χαρακτήρες του xml ξεκινώντας απο το πρώτο "<" μέχρι το τελευταίο ">" και να περάσεις αυτό σαν είσοδο στον parser.

_________________
Chief Software Engineer @ PinApps.com
Κωνσταντίνος Πολυχρόνης
Πρόσθεσε την εφαρμογή σου:


27 Apr 2009, 15:02
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 12 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users and 80 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware.