× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Paul,

The problem is due to case-sensitivity. Because XML's specs define it as a case-sensitive language, you could potentially have multiple XML elements named 'MYROOT', 'MyRoot', 'myRoot', and 'myroot', and they'd all be considered different elements! Because they're case sensitive, 'myRoot' is different from 'myroot'!

RPG's default option is 'case=lower' (I don't know why they picked that as the default, IMHO, it's not intuitive *AT* *ALL*) Which means that the RPG variable name will be converted to all lowercase when matching the XML variable.

If you follow what I said so far, you should understand why your code does not not. Your XML elements are 'myRoot' and 'aString', and your RPG variables (thanks to case=lower) are considered 'myroot' and 'astring'. They don't match!

Make your XML look as follows, and it will work:

XML = '<myroot><astring>Hello world</astring></myroot>';

And that will work fine for the trivial example program you posted. In the real world, of course, we don't usually have control over the contents of our XML documents! They are sent by someone else, and we have to read them with XML-INTO -- at least, that's been my experience.

In that situation, you'll probably want to specify the case=any option:

XML = '<myRoot><aString>Hello world</aString></myRoot>';

Options = 'doc=string allowextra=yes allowmissing=yes case=any';
XML-Into myRoot %XML(XML: Options);

(Don't forget to include the Options variable in the %XML BIF... you forgot it in your code sample.)

The case=any makes the RPG variable name case-insensitive (in violation of XML standards... but it rarely comes up in the real world) so now your variable being 'myroot' will match an XML document being 'myRoot'.

Unfortunately, there's no way for RPG to see your variable name in the same case as you typed the source code. You either have to go case=any (case insensitive), case=lower (default; converts var name to all lowercase) or case=upper (converts var name to all upper -- I can't imagine ever using this.)

Good luck


On 12/26/2010 4:23 PM, Paul Nicolay wrote:
DmyRoot DS Qualified
D aString 255 Varying

DXML S 4096 Varying
DOptions S 255 Varying

/free
XML = '<myRoot><aString>Hello world</aString></myRoot>';

Options = 'doc=string allowextra=yes allowmissing=yes ';
XML-Into myRoot %XML(XML);


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.