Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6699377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:41:18+00:00 2026-05-26T06:41:18+00:00

How could I get the data from a xml, which is generated with php,

  • 0

How could I get the data from a xml, which is generated with php, in java.
I need the data to display it in a listview in my android app.

The phpcode take the data form the mysqlquery and fetch the array in the variabel xml and put it over echo out. The data for the mysqlquery are from the android app over POST.

phpcode:

//MySQL zugangsdaten
$server = "server";
$datenbank = "database";
$username = "username";
$passwort = "password";

//Verbindung zur MySqldatenbank herstellen
$link = mysql_connect($server, $username, $passwort);
if (!$link) die(mysql_error());

//Datenbank auswählen
$db = mysql_select_db($datenbank, $link);
//<---- End Login ---->

$_linie = htmlspecialchars(mysql_real_escape_string($_POST["linie"]), ENT_COMPAT);
$_richtung = htmlspecialchars(mysql_real_escape_string($_POST["richtung"]), ENT_COMPAT);

$sql_befehl = "SELECT * From Kontrolleure where linie = '$_linie' AND richtung = '$_richtung'";
$query = mysql_query($sql_befehl, $link);
if(mysql_error())
            {
                die(mysql_error());
            }

while($result = mysql_fetch_array($query, MYSQL_ASSOC))
        {   
            $count = $count + 1;
            $xml = $xml."<Konduktor>";
            $xml = $xml."<id>".$result['id']."</id>";
            $xml = $xml."<linie>".$result['linie']."</linie>";
            $xml = $xml."<endstation>".$result['richtung']."</endstation>";
            $xml = $xml."<station>".$result['station']."</station>";
            $xml = $xml."<zeit>".$result['zeit']."</zeit>";
            $xml = $xml."</Konduktor>";
        }
echo "<Konduktors count=\"$count\">";
echo $xml;
echo "</Konduktors>";

the xml response looks like this:

<Konduktors count="3">
   <Konduktor>
      <id>29</id>
      <linie>S23</linie>
      <endstation>Langenthal</endstation>
      <station>Brugg AG</station>
      <zeit>17:36:34</zeit>
   </Konduktor>
   <Konduktor>
      <id>30</id>
      <linie>S23</linie>
      <endstation>Langenthal</endstation>
      <station>Lupfig</station>
      <zeit>17:37:12</zeit>
   </Konduktor>
   <Konduktor>
      <id>32</id>
      <linie>S23</linie>
      <endstation>Langenthal</endstation>
      <station>Birr</station>
      <zeit>16:23:30</zeit>
    </Konduktor>
</Konduktors>

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:41:18+00:00Added an answer on May 26, 2026 at 6:41 am

    JAXB would handle that easily:

    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.JAXBException;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlRootElement;
    import java.io.StringReader;
    import java.util.ArrayList;
    import java.util.List;
    
    public class JaxbExample {
        public static void main(String[] args) throws JAXBException {
            String xml =
                    "<Konduktors count=\"3\">\n" +
                    "   <Konduktor>\n" +
                    "      <id>29</id>\n" +
                    "      <linie>S23</linie>\n" +
                    "      <endstation>Langenthal</endstation>\n" +
                    "      <station>Brugg AG</station>\n" +
                    "      <zeit>17:36:34</zeit>\n" +
                    "   </Konduktor>\n" +
                    "   <Konduktor>\n" +
                    "      <id>30</id>\n" +
                    "      <linie>S23</linie>\n" +
                    "      <endstation>Langenthal</endstation>\n" +
                    "      <station>Lupfig</station>\n" +
                    "      <zeit>17:37:12</zeit>\n" +
                    "   </Konduktor>\n" +
                    "   <Konduktor>\n" +
                    "      <id>32</id>\n" +
                    "      <linie>S23</linie>\n" +
                    "      <endstation>Langenthal</endstation>\n" +
                    "      <station>Birr</station>\n" +
                    "      <zeit>16:23:30</zeit>\n" +
                    "    </Konduktor>\n" +
                    "</Konduktors>";
            Object object = JAXBContext.newInstance(Konduktors.class).createUnmarshaller().unmarshal(new StringReader(xml));
            System.out.println(object);
        }
    
        @XmlRootElement(name = "Konduktors")
        static class Konduktors {
            private List<Konductor> konductors = new ArrayList<Konductor>();
    
            @XmlElement(name = "Konduktor")
            public List<Konductor> getKonductors() {
                return konductors;
            }
    
            public void setKonductors(List<Konductor> konductors) {
                this.konductors = konductors;
            }
    
            @Override
            public String toString() {
                return "Konductors{" +
                        "konductors=" + konductors +
                        '}';
            }
        }
    
        static class Konductor {
            private int id;
            private String linie;
            private String endstation;
            private String zeit;
    
            public int getId() {
                return id;
            }
    
            public void setId(int id) {
                this.id = id;
            }
    
            public String getLinie() {
                return linie;
            }
    
            public void setLinie(String linie) {
                this.linie = linie;
            }
    
            public String getEndstation() {
                return endstation;
            }
    
            public void setEndstation(String endstation) {
                this.endstation = endstation;
            }
    
            public String getZeit() {
                return zeit;
            }
    
            public void setZeit(String zeit) {
                this.zeit = zeit;
            }
    
            @Override
            public String toString() {
                return "Konductor{" +
                        "id=" + id +
                        ", linie='" + linie + '\'' +
                        ", endstation='" + endstation + '\'' +
                        ", zeit='" + zeit + '\'' +
                        '}';
            }
        }
    }
    

    Other options include XStream or XMLBeans for higher-level abstractions and dom4j or JDOM for lower-level ones–you have to do more work with these but have a lot more flexibility.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question. How could I get the data from a google search
for a certain project, I need some way to parse XML and get data
I am trying to get the data from input xml message using functoids. But
In my application I want to post from my android application XML data in
I just started using SimpleXML to get a feed and display data from that
I have an iPhone app which communicates with a server to get the data
hi im doing a loop so i could get dict of data, but since
Wondering if I could get some advice and direction on this following requirement: Need
I need to do the following and i was wondering if i could get
Could I get some confirmations from the community that I'm not going mad, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.