Announcement

Collapse
No announcement yet.

Using XML to change settings.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using XML to change settings.

    Hi, I need some help to overcome an error writing a setting using XML in my custom project based on tunneler.c.

    I am using SDK version "Lantronix Xport Pro V5.4.0.2R1".
    Here is my(edited) code snippet;

    static const char *xmlConfig =
    "<?xml version="1.0" standalone="yes"?>"
    "<configrecord>"
    "<configgroup name="snmp">"
    "<configitem name="traps">"
    "<value name="primary destination">";


    static const char *xmlConfig2 =
    "</value>"
    "</configvalue>"
    "</configitem>"
    "</configgroup>"
    "</configrecord>";


    strcpy(config_string, xmlConfig);

    snprintf(tempString, sizeof(tempString), ""%u.%u.%u.%u"", ElanIPArray[5],ElanIPArray[6],ElanIPArray[7],ElanIPArray[8] );
    strcat(config_string, tempString);
    strcat(config_string, xmlConfig2);
    if(! StreamInitWithConstCharPtr(&bufferStream, config_string))
    {
    TLOG(TLOG_SEVERITY_ERR, "Failed to init stream.");

    // return;
    }

    if(! XMLImportFromStream(&bufferStream.inStream, sampleErrorHandler, NULL))
    {
    TLOG(TLOG_SEVERITY_ERR, "XML not processed!");
    // return;
    }

    ElanIPArray is an array of uint_8 data that contains the IP address as four bytes.

    This is a capture of "config_string" that is used by the XML import function.

    <?xml version="1.0" standalone="yes"?><configrecord><configgroup name="snmp"><configitem name="traps"><value name="primary destination">"192.168.0.5"</value></configvalue></configitem></configgroup></configrecord>


    The error "XML not processed!" occurs.

    Thanks in advance.

  • #2
    You need to include the import group of the XML record.

    Comment


    • #3
      Thanks for your reply.

      I did have that as an import, this is the import list;

      #include "evolution.h"
      #include "evolution_defines.h"
      #include "evolution_cli.h"
      #include "evolution_http.h"
      #include "evolution_libs.h"
      #include "evolution_net.h"
      #include "evolution_serial.h"
      #include "evolution_stdlib.h"
      #include "evolution_tlog.h"
      #include "evolution_xml.h"
      #include "evolution_stdio.h"
      #include "startup.h"
      #include "evolution_socket.h"
      #include "evolution_snmp.h"
      #include "evolution_list.h"
      #include "evolution_ber.h"
      #include "evolution_stream.h"

      I discovered I had a few things potentially wrong.

      Firstly, the <configrecord> statement should have been <configrecord version="0.1.0.0T0"> I believe.

      The second thing I think I got wrong was I had the IP address in quotes.

      So I corrected the code to this;

      char tempString[50];
      char config_string[256];
      struct input_stream_with_const_char_ptr bufferStream;


      static const char *xmlConfig =
      "<?xml version="1.0" standalone="yes"?>"
      "<configrecord version="0.1.0.0T0">"
      "<configgroup name="snmp">"
      "<configitem name="traps">"
      "<value name="primary destination">";


      static const char *xmlConfig2 =
      "</value>"
      "</configvalue>"
      "</configitem>"
      "</configgroup>"
      "</configrecord>";


      strcpy(config_string, xmlConfig);

      snprintf(tempString, sizeof(tempString), "%u.%u.%u.%u", ElanIPArray[5],ElanIPArray[6],ElanIPArray[7],ElanIPArray[8] );
      strcat(config_string, tempString);
      strcat(config_string, xmlConfig2);

      if(! StreamInitWithConstCharPtr(&bufferStream, config_string))
      {
      TLOG(TLOG_SEVERITY_ERR, "Failed to init stream.");

      // return;
      }

      if(! XMLImportFromStream(&bufferStream.inStream, sampleErrorHandler, NULL))
      {
      TLOG(TLOG_SEVERITY_ERR, "XML not processed!");
      // return;
      }


      The string generated was;

      <?xml version="1.0" standalone="yes"?><configrecord version="0.1.0.0T0"><configgroup name="snmp"><configitem name="traps"><value name="primary destination">192.168.0.6</value></configvalue></configitem></configgroup></configrecord>

      I still get the same error message, "XML not processed!".

      I must have something wrong still!

      Thanks.




      Comment


      • #4
        This group must be included:
        <configgroup name = "xml import control">

        Comment


        • #5
          Thanks for the reply but that was not the issue.

          I made an obvious mistake on the construction of the string, I had an unnecessary statement included.

          This is the correct string;

          static const char *xmlConfig2 =
          "</value>"
          "</configitem>"
          "</configgroup>"
          "</configrecord>";



          Resolved and working.

          Comment

          Working...
          X