creating attributes with ofxXmlSettings

hi,

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?

ben

Hi ben,

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

Just for testing, in testApp.mm, 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 https://github.com/openframeworks/ofxXmlSettings/blob/master/addons/ofxXmlSettings/src/ofxXmlSettings.h 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.

eg:
211
168

instead of:

211
168

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
XML.getValue(“STROKE:PT:X”,0,0)
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?

thanks,
dan

i should still just use
XML.getValue(“STROKE:PT:X”,0,0)
and it should work fine?

Yep.

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.

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

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?

thanks,
dan

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

  
  
XML.getNumTags("statuses:status");  
  
vs  
  
XML.pushtag("statuses");  
XML.getNumTags("status");  
  

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:
https://github.com/openframeworks/openFrameworks/blob/master/addons/ofxXmlSettings/src/ofxXmlSettings.h#L89

//-- 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.

https://github.com/openframeworks/openFrameworks/blob/master/addons/ofxXmlSettings/src/ofxXmlSettings.cpp#L272

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