Go Down

Topic: Retrieve node data from XML file (Read 108 times) previous topic - next topic

yallappa

 I'm using Arduino and esp8266 to get data access an XML file and to display on LCD. I send GET request to my web service to receive XML file as response. But it returns like
+IPD,192:<?xml version="1.0" encoding="utf-8"?>
<empdetailsClass xmlns:xsd="http://www.w3.org/2001/XMLSch... xmlns:xsi="http://www.w3.org/2001/XMLSch... xmlns="http://tempuri.org/" />
OK

This is my XML file
Code: [Select]

<emp>
    <eid>1001</eid>
    <name>ramesh</name>
    <DOJ>23-09-2001</DOJ>
    <salary>10000</salary>
</emp>




I am using AT commands to connect to server.
I have a limitation that I have to program into arduino only, not esp8266.
Because I have to interface LCD, My esp-01 module have only two GPIO pins.

Please, Suggest me code to get node data from XML file.

PaulS

Quote
Please, Suggest me code to get node data from XML file.
Please explain why you need to use XML.

Writing an XML parser is not all that difficult. I wrote one in about 4 hours (I don't claim that it was entirely bug free, or covered every case, but it did handle all the files it needed to). But, that was on a PC that had a lot of memory. Fitting the XML parser into the code and data memory area of the Arduino might be challenging.

If the PC is sending data, make the stupid thing send data that is more Arduino-friendly. If you seem to think that you can't, make a GET request to a different script, and have that script make the GET request to get the XML file, and do the parsing. Having the script send back
Quote
<eid=1001; name=ramesh; DOJ=23-09-2001; salary=10000>
will make for orders of magnitude easier parsing.

PaulS

By the way, I can't see that ANY of that data will prove useful on the Arduino. Are you planning to make it dispense cash to pay salaries?

yallappa

Thank you, my problem with reading xml tags solved.
Code: [Select]

char *starttags[] = { "<eid>", "<name>", "<DOJ>" };
char *endtags[] = { "</eid>", "</name>", "</DOJ>" };

String method = "GET /company/emp.asmx/empdetails?empCode=\r\n";
  method += "HTTP/1.1\r\n ";
  method += "Host: 192.168.10.1\r\n";
  method += "Connection: Close\r\n";

content = String(sendData(method,20000,DEBUG));
  Serial.println(content);

void readtags()
{
 for (int i=0; i<3; i++ )
     {
         delay(1000);
         // Find the <Value> and </Value> tags and make a substring of the content between the two
         int startValue = content.indexOf(starttags[i]);
         int endValue = content.indexOf(endtags[i]);
        // Serial.println(starttags[i]);
         int k = strlen(starttags[i]);
         tagdata[i] = content.substring(startValue + k, endValue);    // + 7 to make the index start after the <Value> tag
         Serial.println(tagdata[i]);
      }
}



By using this code block i am reading the required tags data. The sendData will send get method and returns the respone(whole XML file) in serial monitor.

But I have another problem now, the data is stored and printed on serial monitor once currectly. But next execution of the loop it is not printing all the XML file but only part of it.
Why?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy