ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Variable XML reading

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

  • Variable XML reading

    Hello everyone,
    I am encoding an XML and it is variable, that is, they do not always send me the same tags. I am using XML-INTO but obviously it gives me an error since when the structure changes it does not match the structure that I have declared.
    What I can do? I have thought about using XML-SAX, but since I am new to this world, I don't know if there is a simpler way.

    Example 1
    PHP Code:
    .
     .
     .      
                      </
    Persoonsgegevens>
                      <
    HuidigAdres>
                        <
    Straat></Straat>
                        <
    Huisnummer>
                          <
    N>5/N>
                        </
    Huisnummer>
                        <
    Postcode>
                          <
    N></N>
                          <
    A></A>
                        </
    Postcode>
                        <
    Plaats></Plaats>
                        <
    Land></Land>
                      </
    HuidigAdres>
                      <
    VorigAdres>
                        <
    Straat></Straat>
                        <
    Huisnummer>
                          <
    N></N>
                        </
    Huisnummer>
                        <
    Postcode>
                          <
    N></N>
                          <
    A></A>
                        </
    Postcode>
                        <
    Plaats></Plaats>
                        <
    Land></Land>
                      </
    VorigAdres>
                      <
    Contracten>
                        <
    Eigen>
                          <
    Contract>
    .
    .

    Example 2
    PHP Code:
    .
     .
     .  
                      </
    Persoonsgegevens>
                      <
    HuidigAdres>
                        <
    Straat></Straat>
                        <
    Huisnummer>
                          <
    N></N>
                        </
    Huisnummer>
                        <
    Postcode>
                          <
    N></N>
                          <
    A></A>
                        </
    Postcode>
                        <
    Plaats></Plaats>
                        <
    Land></Land>
                      </
    HuidigAdres>
                      <
    Contracten>
                        <
    Initiator>
                          <
    Contract>
                            <
    DeelnemerNummer></DeelnemerNummer>
                            <
    SoortOvereenkomst>
    .
    .

    thank you very much




  • #2
    XML-INTO supports option "allowmissing=yes" which means it does not error if they omit tags that are on your DS. In this scenario, your DS field will keep whatever value it had vbefore XML-INTO.

    For your scenario, I think it's recommended that you use allowmissing=yes, but then since you will not get an error if a vital tag is missing, you should test that each field in your DS is popupated as expected.
    In most cases testing for a blank value would be enough (make your you give each field in your DS a proper initialisation value), but probably not for nested elements or numeric values. In which case, make sure use the countprefix option. This lets you specify for any field, a companion numeric field that contains the number of instances. E.g. you specify countprefix="num_" and numeric field num_VorigAdres in your DS, next to VorigAdes. num_VorigAdres will be 0 if VorigAdes was omitted, else it will be = or more (the number of instances.

    Note it also supports option "allowextra=yes" which means it will not error if they send extra tags that are not in your DS.

    For full details on all these options:

    Comment


    • #3
      Originally posted by Vectorspace View Post
      XML-INTO supports option "allowmissing=yes" which means it does not error if they omit tags that are on your DS. In this scenario, your DS field will keep whatever value it had vbefore XML-INTO.

      For your scenario, I think it's recommended that you use allowmissing=yes, but then since you will not get an error if a vital tag is missing, you should test that each field in your DS is popupated as expected.
      In most cases testing for a blank value would be enough (make your you give each field in your DS a proper initialisation value), but probably not for nested elements or numeric values. In which case, make sure use the countprefix option. This lets you specify for any field, a companion numeric field that contains the number of instances. E.g. you specify countprefix="num_" and numeric field num_VorigAdres in your DS, next to VorigAdes. num_VorigAdres will be 0 if VorigAdes was omitted, else it will be = or more (the number of instances.

      Note it also supports option "allowextra=yes" which means it will not error if they send extra tags that are not in your DS.

      For full details on all these options:
      https://www.ibm.com/support/knowledg...0925081031.htm
      Thank you very much, it worked perfectly for me.

      Comment

      Working...
      X