Go Down

Topic: Retrieve node data from XML file (Read 1 time) previous topic - next topic


 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/" />

This is my XML file
Code: [Select]


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.


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
<eid=1001; name=ramesh; DOJ=23-09-2001; salary=10000>
will make for orders of magnitude easier parsing.
The art of getting good answers lies in asking good questions.


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?
The art of getting good answers lies in asking good questions.


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:\r\n";
  method += "Connection: Close\r\n";

content = String(sendData(method,20000,DEBUG));

void readtags()
 for (int i=0; i<3; i++ )
         // 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

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.

Go Up