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.