ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

XML-INTO Consuming XML strings with a Namespace in the Tags

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

  • XML-INTO Consuming XML strings with a Namespace in the Tags

    This is the first time I have used XML-INTO. The XML strings I must consume have a namespace in the tags. I can't create field names in data structures that have a colon in them. How do I parse XML strings like this? Do I have to pre-parse the strings removing the namespace out of the tags before running XML-Into? Thanks.

    <bo:Workorder>
    <bo:WorkorderID>
    <bo:Property>LEDPRP</bo:Property>
    </bo:WorkorderID>
    <bo:WorkorderDesc>Carpet Stain</bo:WorkorderDesc>
    <bo:RoomCode>102</bo:RoomCode>
    <bo:RoomDesc>Deluxe King</bo:RoomDesc>
    <bo:HotelDate>2018-06-22</bo:HotelDate>

  • #2
    Take a look at the 'ns' and maybe also the 'nsprefix' options for XML-INTO



    You could use ns=merge, which converts the colon to an underscore, and therefore "bo:Workorder" would map to RPG variable bo_Workorder. I personally don't like that option, because the creator of the XML document should have the option to change their namespaces to any arbitrary value (as long as it matches the same namespace url) and its not practical to change the RPG program each time they change their namespace abbreviation. But, if you know it'll never change, that might be an option for you.

    The better choice would be ns=remove. This simply strips the namespace so that bo:Workorder would map to an RPG variable named Workorder. When you do that, if you want to know the namespace for some reason, you can use nsprefix to map the namespace itself into a separate variable. Usually, in my experience, nsprefix isn't needed, and you can just strip it and be fine... but, the option is there if you need it.

    Comment

    Working...
    X