Go Down

Topic: XML - Elements with the same name. (Read 70 times) previous topic - next topic

fufs

Hi

I'm trying to do a esp8266 PC hardware monitor, but I'm using Arduino IDE to write the code. I found a perfect PC program for this job (MSI Afterburner) and it basically starts a server, in which it updates a XML document every second. I want to be able to take some data off it and put it on a oled display. I found a guy (INT 21h;, http://blindage.org/?p=8366) who made a similar project and he used a library called "tinyXML2". Using his program as a foundation, I started to write my own code.

His Code:

Code: [Select]

    HTTPClient http;
    http.begin(Url);
    Serial.println(Url);
    int httpCode = http.GET();
    if (httpCode > 0) {
      Serial.println(httpCode);
      if (httpCode == HTTP_CODE_OK) {
        String payload = http.getString();
        XMLDocument doc;
        doc.Parse( payload.c_str() );

        XMLElement* dayElement = doc.FirstChildElement( "info" )->
        FirstChildElement( "weather" )->FirstChildElement( "day" )->FirstChildElement( "day_part" );

        const char* temp = dayElement->FirstChildElement( "temperature" )->GetText();
        const char* pressure = dayElement->FirstChildElement( "pressure" )->GetText();
        const char* dampness = dayElement->FirstChildElement( "dampness" )->GetText();
        const char* wind = dayElement->FirstChildElement( "wind_speed" )->GetText();
        const char* wind_direction = dayElement->FirstChildElement( "wind_direction" )->Attribute("id");
        const char* weather_code = dayElement->FirstChildElement( "weather_code" )->GetText();

}


his XML (structure):

Code: [Select]

<a>
    <b>
        <c>text</c>
        <d>value</d>
    </b>
</a>


And this is my problem. The structure of my XML looks something like this:

Code: [Select]

<a>
    <b>
        <c>text</c>
        <d>value</d>
    </b>
    <b>
        <c>text2</c>
        <d>value2</d>
    </b>
</a>


I found something called NextSiblingElement, but I can't figure out how it works.

Can anyone help???



P.S. Sorry for my bad english.

PaulS

Quote
I found something called NextSiblingElement, but I can't figure out how it works.
Was that swept under the rug in your dorm? WHERE did you find it?

Do you know what a Sibling is?
The art of getting good answers lies in asking good questions.

fufs

Sibling - each of two or more children or offspring having one or both parents in common; a brother or sister.

I'm new to Arduino and XML. All I want is some help. Not hate.

PaulS

Sibling - each of two or more children or offspring having one or both parents in common; a brother or sister.

I'm new to Arduino and XML. All I want is some help. Not hate.
Where did THAT come from?

If you have a pointer to an XMLNode, then you can use NextSibling() to get the next sibling. That assumes that you understand what a sibling is. Hence my question.

Once you have the next sibling, you can get the data from it, just like you got the data from the first sibling.
The art of getting good answers lies in asking good questions.

fufs

What? Where did I find the NextSiblingThing? I found it on a GitHub forum. Can't remember which one.

Go Up