help with XML tags?

Hi all,

I’m trying to use my OF program to write to an XML file that another (non OF) program reads from.

Because that program expects the XML in it’s own format, I can’t change the tag structure.

I’m trying to change the image file in the following tags:

  
<XmlExchange>  
    <label name="MediaReadin" type="1">  
        <a string="image_0077.bmp" />  
    </label>  
</XmlExchange>  

Can I get at the string data using any of the ofxXmlSettings calls?

Calling XML.tagExists(“XmlExchange:label:a”); on the file returns true, but I can’t get XML.getValue(“XmlExchange:label:a”, “bah”); to return anything, despite trying a variety of permutations.

I’m not sure what to do about the “name=”, “type=”, “string=” parts of the tags.

Maybe I just have to read/write to the xml file like a text file? But I’m hoping to avoid that.

Thanks for any suggestions. -Camille

those are attirbutes and since 0061 you can read them too:

XML.getAttribute(“XmlExchange:label:a”, “string”, “bah”);

Oh! Thanks Arturo.

I’m still using 0060, so will switch over now.

Many Thanks again for helping. -C

Uh oh. After downloading 061 I’m still having problems:

Here is the XML again:

  
<XmlExchange>  
    <label name="MediaReadin" type="1">  
        <a string="image_0077.bmp" />  
    </label>  
</XmlExchange>  

If I do the following, fexists returns true, so I think I have the tag syntax right:

  
bool fexists=0;  
fexists = XML.tagExists("XmlExchange:label:a");  
if(fexists)printf("found tag \n");  

but, if I do this, the value of my xmlstring var is NULL?

  
string xmlstring;  
xmlstring=XML.getAttribute("XmlExchange:label:a", "string", "bah");  
printf("value is %s\n",xmlstring);  

I’ve tried replacing the “string” with “string=”, and looking at the attributes of the outer tag: XML.getAttribute(“XMLExchange:label”, “name”, “bah”) but still to no avail?

I even tried to print directly in case there was something going on with my string variable:

printf(“value is %s\n”, XML.getAttribute(“XmlExchange:label:a”, “string”, “bah”));

Am I missing something? Many thanks. -C

Replying to myself - YES!

  
printf("value is %s\n", xmlstring.c_str( ));  

feeling sheepish. It’s been awhile since I’ve coded.

Is there a good OF example of string handling anywhere?

best -C

I get all kinds of things wrong with C++ strings b/c they’re so different than java/ruby/actionscript strings. There’s a good reference here.

www.cplusplus.com/reference/string/
or
http://www.learncpp.com/cpp-tutorial/17-…-tdwstring/

You really don’t need to use c strings very often. printf() is the only time I ever do, but for the most part you can use c++ strings the same as strings in other (friendlier-ish) languages.