Picking apart XML with tinyXML - value at the end of an Attribute?

jolly

VIP Member
Hi All,

I am developing some C++ code to interpret or modify XML documents that are being passed to or replied back from xmlCallObject... I'm using the tinyXML library for this just because... it's the first one I looked at and seems useful enough.

What I have noticed is that the BSFN parameters have a name-value pair, then the actual parameter value after that. For example:

<?xml version='1.0' encoding='UTF-8' ?>
<jdeRequest pwd='' role='*ALL' type='callmethod' user='' comment='' session='' environment='' sessionidle=''>
<callMethod app='XMLTest' name='GetAlphaNameFromAB'>
<returnCode code='0'/>
<params>
<param name='mnAddressNumber'>0</param>
<param name='szNameAlpha'></param>
</params>
</callMethod>
</jdeRequest>

When I work my way through this document with tinyXML I can grab an TiXmlElement for the <params> element, and within that iterate through the Attributes (TiXmlAttribute) for each Attribute. For each Attribute I can access the Name() which returns "name" and the Value() which returns "mnAddressNumber" or "szNameAlpha"... but I am interested in the bit after that - in the case if the mnAddressNumber, I want to set the 0 that is there to an address number for the request and in the case of szNameAlpha I want to grab the string there in the response... But I can't work out how that can be done... What is the term for that thing that comes after the attribute Value?

I think I'm missing something obvious here!

TIA for any advice!
JohnO
 
... I'm sure that the answer should be that it is the Value() of the <param> element... but tinyXML returns "param"...
 
Hi JohnO,

While I'm only slightly experienced in tinyXML, I think you may be confusing attributes and elements. The <params> element contains a list or array of <param> elements. Each <param> element has an attribute called name with the data structure member as the value. I think you are interested in the value of the <param> element, which would be the 0 for the one with the mnAddressNumber name attribute.

Craig
 
Hi Craig,

Yes, I agree... but when I access the Value() method of the param element it returns "param" but you and I expected to return "0"!

However, I found that the element has a GetText() method that returns the expected "0" or whatever value trails the attribute name-value pair. So I am sort of half way there...

Now... if I invoke the SetValue() method of the param element it renames it with that value... i.e. if the param element is

<param name='mnAddressNumber'>0</param>

and I say param.SetValue("1000")

then it becomes

<1000 name='mnAddressNumber'>0</1000>

!!! It's like I am one level out. There's no SetText() method of the Element class...
 
Maybe that's why it's tinyXML. Perhaps we need midsizeXML:p. Have you tried the Xerces API in the JDE libs?
 
Heh! There's a tinyXML2 maybe I should have started there! <facepalm>

I did see the XRCS stuff but didn't want to rely on JDE API if I can avoid it as this is a standalone application (that will talk to jde just using XML and xmlCallObject)... but might end up there as a colleague used it elsewhere and I hear it actually does what it says on the tin...
 
I did see the XRCS stuff but didn't want to rely on JDE API if I can avoid it as this is a standalone application (that will talk to jde just using XML and xmlCallObject)... but might end up there as a colleague used it elsewhere and I hear it actually does what it says on the tin...

Of course the JDE API is just a wrapper around https://xerces.apache.org/ (actually I think it is a wrapper around IBM's implementation???). If you used just straight https://xerces.apache.org/ the knowledge you would gain using that API would be largely applicable to creating/parsing XML data in JDE as well.
 
Thanks BOster - might be the best option for ongoing maintainability etc.

FEI I did get this resolved in the mean time with tinyXML. The missing link was that there is a Text element (TiXmlText) child node of the param element containing the element's text, and that can be accessed through GetText() and SetText()... The Value of the param element really is the name of the element "param".

Cheers
JohnO
 
Thanks for the info, JohnO. The fact that the element is called param surely made it confusing.

Craig
 
Thanks BOster - might be the best option for ongoing maintainability etc.

FEI I did get this resolved in the mean time with tinyXML. The missing link was that there is a Text element (TiXmlText) child node of the param element containing the element's text, and that can be accessed through GetText() and SetText()... The Value of the param element really is the name of the element "param".

Cheers
JohnO

Yeah and the Attribute with name "name" was even worse!!!
 
Back
Top