creating attributes with ofxXmlSettings


I think its not possible to create Attributes for Tags. Am I right?
If yes, maybe we can add this functionality?
Does tinyXml provide that?


Hi ben,

It’s possible, I just did it this morning while testing the supplied ofxXmlSettings…

Just for testing, in, testApp::mouseDragged(), I added:

int tagNum = XML.addTag(“PT”);
XML.setValue(“PT:X”, x, tagNum);
XML.addAttribute(“PT:X”,“test_attr”,1,0); // added for test
XML.setValue(“PT:Y”, y, tagNum);

And I then got this in my saved XML file:

211 168

thanks for your help! I used the code from github here to llok up methods but this is outdated! there aren’t any addAttribute methods, so I was wondering!

I’m using the downloaded 0.062 and will try the latest github master branch as soon as I figure out this new-fangled auto-generated project file stuff!

sorry if this is a little unrelated… but is it possible to remove any/all the tags so it’s just a plain text file? Thanks.


instead of:


Hi, I saw your other threads asking about text file saving… so, no, it’s not possible (as far as I know) using the ofxXmlSettings/TinyXML add-on alone. The methods can help you convert the xml content to text within the application, but to save as an external text file, that’s not supported in this add-on

in this case when reading from the file, i should still just use
and it should work fine?

i’m making a twitter app and it passes me some xml and i’m attempting to read it with SMLsettings and i’m having some trouble.
the beginning of the file looks like this:

<?xml version="1.0" encoding="UTF-8"?>

does the xml parser ignore that first line or do i need to delete that one?


i should still just use
and it should work fine?


does the xml parser ignore that first line or do i need to delete that one?

You should keep the first line, the XML parser isn’t going to read that as a node, that’s actually the XML declaration.

ok. here is the problem i am having.

bool isFileLoaded = XML.loadFile("tweetlist.xml");  
cout << isFileLoaded << " that the file was loaded " << endl;  
//bool isBufferLoaded = XML.loadFromBuffer(replyMsg.c_str());  
//cout << isBufferLoaded << " that the string buffer was loaded ";  
int numTags = XML.getNumTags("statuses:status");  
cout << numTags << " num tags---" << endl;  
	for(int i = 0; i < 25; i++)  
	timeLine[i] = XML.getValue("statuses:status:created_at","--",i) + " " +XML.getValue("statuses:status:text","--",i);  
	cout << timeLine[i] << endl;  

i even hand edited a file to look like this and i still only get one numtag returned for “statuses:status”
i thought maybe somewhere in all the extra tags something was tripping up the parser but even in this simple example it fails.

  <created_at> wed2011date </created_at>  
  <text>manual test2</text>  
  <created_at>Wed Nov 30 03:15:03 +0000 2011</created_at>  
  <created_at>Wed Nov 30 03:08:18 +0000 2011</created_at>  
  <text>i want more entries to show up</text>  

response to that file:

1 that the file was loaded  
1 num tags---  
wed2011date manual test2  
-- --  
-- --  

am i missing something simple? i’ve used xmlsettings in a couple other cases successfully and xml demo app runs fine. so what to try now?


it seems that these are not equal and i thought they were:


the second works great for me. the first only gives me one response.

Yeah, I might be wrong about this but I think that the colon delimited getTag (i.e. “statuses:status”) only returns the first instance that it finds, rather than being a real e4x implementation like you find in Javascript. Using pushtag() is definitely the way to go.

Yes it says so in the code:

//-- numTags
//this only works for tags at the current root level
//use pushTag and popTag to get number of tags whithin other tags
// both getNumTags(“PT”); and getNumTags(“PT:X”); will just return the
//number of tags at the current root level.

// Either find the tag specified, or the first tag if colon-seperated.