0

I am receiving xml that looks like this, and using XMLBeans to parse it:

<reply xmlns="http://www.xmlisfun.com/abc/def/1.0">
    <item-list>
        <item>
            <item-data>data</item-data>
        </item>
    </item-list>
</reply>

There is a complex type in the schema called ItemListReplyType that is imported.

Due to someone mucking around with the schema definition, the objects parsed by XMLBeans will not properly generate an ItemListReplyType object. The ItemListReplyType object will always say that it doesn't contain any "item" objects. This is due to some namespace conflict.

I noticed that when I parse the following, I am able to retrieve my object array normally in the code from the ItemListReplyType object (array is not empty - "item" objects are present as expected).

<reply xmlns="http://www.xmlisfun.com/abc/def/1.0">
    <item-list>
        <prefix:item xmlns:prefix="http://www.xmlisfun.com/particular_namespace">
            <prefix:item-data>data</prefix:item-data>
        </prefix:item>
    </item-list>
</reply>

Needless to say, the proper solution would be to fix the hack made to the schema and re-generate all the XMLBeans objects. However, that would have been a mighty good fix a year ago before the project was built on all these objects. I'd rather not mess with that.

Is there a way to just easily modify the XML to add the namespace and prefix to all the item elements and its children? I'm fighting the urge to do it manually and be done with it. I figured I would check here for help.

Thanks.

Cheese Daneish
  • 1,030
  • 7
  • 15

1 Answers1

1

Not sure what form your XML is in. Your proposed mod is overly complex, you just need a tweak to the item element to add xmlns="blah". Might be easy to just do a quick string hack or a proper fix is to run an xsl transform or a parse-fix-serialise step to add the xmlns bit. HTH

davidfrancis
  • 3,734
  • 2
  • 24
  • 21