class methods
- ofxXmlPoco()
- ~ofxXmlPoco()
- addChild()
- addValue()
- addXml()
- clear()
- exists()
- getAttribute()
- getAttributes()
- getBoolValue()
- getFloatValue()
- getInt64Value()
- getIntValue()
- getName()
- getNumChildren()
- getPocoDocument()
- getPocoElement()
- getValue()
- load()
- loadFromBuffer()
- operator=()
- remove()
- removeAttribute()
- removeAttributes()
- removeContents()
- reset()
- save()
- setAttribute()
- setTo()
- setToChild()
- setToParent()
- setToPrevSibling()
- setToSibling()
- setValue()
- toString()
- tokenize()
global functions
The ofXmlPoco is a friendly wrapper around the xml functionality included in the Poco::XML library, in particular the Poco::XML::DOM. You can find some more information on that in the Poco Documentation, but hopefully we've wrapped up everything you might need, so that you don't need to dig into Poco itself. Conceptually you should think of an ofXmlPoco object as an XML document, because that's exactly what it is: it has a root element, some number of children, and a current element that you're pointing at. For instance, if your XML looked like this:
<pictures>
<picture id="0">
<url>http://apicture.co.uk/pic.png</url>
<width>100</width>
<height>100</height>
</picture>
<picture id="1">
<url>http://apicture.co.uk/pic2.png</url>
<width>100</width>
<height>100</height>
</picture>
</pictures>
You load it into an ofXmlPoco document like so:
ofFile file;
file.open("pictures.xml"); // open a file
ofBuffer buffer = file.readToBuffer(); // read to a buffer
ofXmlPoco pictures;
pictures.loadFromBuffer( buffer.getText() ); // now get the buffer as a string and make XML
Now you have an ofXmlPoco document, but you're not pointing at anything yet. The way to select which element you're looking at is by setting the current element, using setTo(const string& path), like this:
pictures.setTo("pictures"); // now we're at the root
or
pictures.setTo("pictures/picture[0]"); // now we're at the first picture.
or
pictures.setTo("pictures/picture[1]"); // now we're at the second picture.
or
pictures.setTo("pictures/picture[@id=0]"); // now we're at the first picture with the id of 0
To traverse, we can use the following methods:
int children = pictures.getNumChildren(); // how many do you have?
pictures.setToParent(); // go up a level
pictures.setToSibling(); // go to the next at your level
pictures.setToPrevSibling(); // go to the previous at your level
To get values, we use getValue(const string& path), like:
pictures.getValue("pictures/picture[0]/url"); // returns "http://apicture.co.uk/pic2.png"
To set values, we use setValue(const string& path, const string& value), like:
pictures.setValue("pictures/picture[0]/url", "http://superpicks.jp/pic1.png"); // sets the element in the DOM
getValue(...)
string ofxXmlPoco::getValue(const string &path)
Returns the value of the current element in the ofXml.
getValue(...)
T ofxXmlPoco::getValue(const string &path, T returnVal)
Returns the value at the node indicated by the path. This can be a path that uses an element:
xml.getValue("picture/pictures[2]/url");
or an attribute:
xml.exists("picture/pictures[2][@id]");
Last updated 火曜日, 19 11月 2024 17:23:46 UTC - 2537ee49f6d46d5fe98e408849448314fd1f180e
If you have any doubt about the usage of this module you can ask in the forum.
If you want to contribute better documentation or start documenting this section you can do so here
If you find anything wrong with this docs you can report any error by opening an issue