[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question on how to Parse an XML document??



   Thanks for your help. The response made absolute since and worked out
   great for me.
   George Baldwin
   From:        Scott Klement <sk@xxxxxxxxxxxxxxxx>
   To:        HTTPAPI and FTPAPI Projects <ftpapi@xxxxxxxxxxxxxxxxxxxxxx>,
   Date:        01/10/2014 07:54 PM
   Subject:        Re: Question on how to Parse an XML document??
   Sent by:        ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
     __________________________________________________________________

   Hello George,
   Perhaps you aren't aware of how to process attributes with HTTPAPI's
   XML
   parser?   You didn't mention how you're going about it, or provide a
   code fragment, so not sure what you're doing, I can only guess.
   But, XML tags are structured like this:
   <tttttt  aaaaa=vvvvv aaaaa=vvvvv>ddddd</ttttt>
   So, "ttttt" is the XML tag name (or 'element name').   aaaaa represents
   an attribute name, of which there can be many.  vvvvv represents an
   attribute value.   ddddd represents the character data inside the tag
   (which the HTTPAPI sample programs simply refer to as 'value').
   Your example tags look like this:
   <fields name="LPM_LIABILITY_SYMBOL">295</fields>
   So you have an XML tag named 'fields' which has one attribute named
   'name', and the value of that attribute is "LPM_LIABILITY_SYMBOL". In
   this example, the character data of the fields tag is '295'.   So when
   HTTPAPI calls your "PARSERTRNXML" subprocedure, HTTPAPI should pass
   these parameters: name="field", value="295", attr(1)="name",
   attr(2)="LPM_LIABILITY_SYMBOL".   (However it's not safe to assume that
   'name' will always be the first attribute.  You should loop through all
   attibutes, instead.)
   So your procedure should look something like this (this is off the top
   of my head, and compeltely untested):
        P ParseRtrnXml    B
        D                 PI
        D   usrdta                        *   value
        D   depth                       10I 0 value
        D   name                      1024A   varying const
        D   path                     24576A   varying const
        D   value                    65535A   varying const
        D   attrs                         *   dim(32767)
        D                                     const options(*varsize)
        D a               s             10i 0
        D attrName                    1024a   varying
        D attrVal                    65535a   varying
         /free
            select;
            when name = 'fields';
               // spin through the attributes of this tag.
               a = 1;
               dow HTTP_nextXmlAttr( attrs: a: attrName: attrVal );
                  select;
                  when attrName = 'name';
                     Result.FieldName = attrVal;
                  when attrName = 'another_attr_name';
                     // handle another attribute name, if needed
                  endsl;
               enddo;
            when name = 'some_tag';
              // handle another tag
            when name = 'other_tag';
              // handle another tag
            endsl;
         /end-free
        P                 E
   Alternately, you could use one of IBM's XML parsers, like XML-INTO. You
   might find that easier to use?
   On 1/10/2014 1:50 PM, CXGBaldwin@xxxxxxxxxxxxx wrote:
   >     __________________
   >     All,
   >     I have two different types of XML documents coming back from a
   vendor
   >     and 1 of them I can not figure out how to parse so I can get the
   field
   >     names along with the values. This is my first time working with
   XML and
   >     parsing.
   >     I am using Scott's freeware for web interaction. We are pulling
   vehicle
   >     information from POLK web service and one of the XML's I get back
   and
   >     try to parse I only get values and not the Field names???  The
   other
   >     XML responses work fine but this one is giving me fits.
   >     NOTE: I am using everything straight from Scott's download except
   the
   >     program managing the user interface and using the command below
   for the
   >     parsing (shown below at bottom as    RC =)
   >     >
   >
   >======================================================================
   >     =================
   >     > Example of problem XML that does not return the field name:
   >     >
   >     >    <fields name="LPM_LIABILITY_SYMBOL">295</fields>
   >     >    <fields name="LPM_LIABILITY_SYMBOL_2008">295</fields>
   >     >    <fields name="LPM_LIABILITY_SYMBOL_2010">295</fields>
   >     >    <fields name="LPM_LIABILITY_SYMBOL_2012">285</fields>
   >     >    <fields name="LPM_LIABILITY_SYMBOL_2014" />
   >     >    <fields name="LPM_LIABILITY_SYMBOL_2016" />
   >     >    <fields name="LPM_PIP_MED_PAY_SYMBOL">490</fields>
   >     >    <fields name="LPM_PIP_MED_PAY_SYMBOL_2008">490</fields>
   >     >    <fields name="LPM_PIP_MED_PAY_SYMBOL_2010">490</fields>
   >     >    <fields name="LPM_PIP_MED_PAY_SYMBOL_2012">475</fields>
   >     >    <fields name="LPM_PIP_MED_PAY_SYMBOL_2014" />
   >     >    <fields name="LPM_PIP_MED_PAY_SYMBOL_2016" />
   >     >
   >     > Looking at LPM_LIABILITY_SYMBOL ---- I do not get back the
   field name
   >     (LPM_LIABILITY_SYMBOL) all I get in the field name is (fields)
   and then
   >     the value of (295)
   >     >
   >
   >======================================================================
   >     ====
   >     > This is one I can parse out when I get the HTML returned with
   no
   >     problems:
   >     >
   >     > <MakeList>
   >     > - <Make>
   >     >    <code>ACU</code>
   >     >    <description>ACURA</description>
   >     >    </Make>
   >     > - <Make>
   >     >    <code>AML</code>
   >     >    <description>AMERICAN LA FRANCE</description>
   >     >    </Make>
   >     > - <Make>
   >     >    <code>AST</code>
   >     >    <description>ASTON MARTIN</description>
   >     >    </Make>
   >     > - <Make>
   >     >
   >     > I get the field name (code) and the value of (ACU) and I get
   the
   >     field(description) and the value (ACURA) and so on.
   >     >
   >     >
   >     >
   >     > Here is the command I am using for both requests in my program:
   >     >
   >     > rc = http_url_get_xml( uri: *null: %paddr(PARSERTRNXML):
   *null);
   >     >
   >     >
   >     >
   >     > Could you please explain what the difference is and how I
   should go
   >     about handling this so I get the field name back? I need it
   because
   >     they can change this XML at anytime and I need to find the exact
   field
   >     name to move it to the proper fields in program.
   >     >
   >     >
   >     > Thanks in advance for any insight you can give me.
   >     >
   >     >
   >     > George
   >     >
   >     >
   >
   >
   >
   >
   -----------------------------------------------------------------------
   > This is the FTPAPI mailing list.  To unsubscribe, please go to:
   > [1]http://www.scottklement.com/mailman/listinfo/ftpapi
   >
   -----------------------------------------------------------------------
   -----------------------------------------------------------------------
   This is the FTPAPI mailing list.  To unsubscribe, please go to:
   [2]http://www.scottklement.com/mailman/listinfo/ftpapi
   -----------------------------------------------------------------------

References

   1. http://www.scottklement.com/mailman/listinfo/ftpapi
   2. http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------