// Example #1: // Create an anchor element #include <Element.h> int main() { // Create a new Element with the name "a" Element a("a"); // All Element's have the operator<< overloaded // So, to output, all you have to do is this: cout << a << endl; return 0; } |
// Example #2: // Create an anchor element and // add some attributes #include <Element.h> int main() { // Create a new Element with the name "a" Element a("a"); // All elements use a Map class // based on the C++ standard map class to hold // their attributes and values. // This makes it extremely easy and intuitive to // make or modify the element's attributes // add an href, a title, and even some style a["href"] = "http://www.buhbird.com"; a["title"] = "Click here for my homepage"; a["style"] = "background-color: lightyellow"; // All Element's have the operator<< overloaded // So, to output, all you have to do is this: cout << a << endl; return 0; } |
// Example #3: // Create an anchor element, add some attributes // and some text #include <Element.h> #include <libXMLTree.h> // So we don't have to keep prefixing // libXMLTree:: to it's functions using namespace libXMLTree; int main() { // Create a new Element with the name "a" Element a("a"); // Add an href, a title, and even some style a["href"] = "http://www.buhbird.com"; a["title"] = "Click here for my homepage"; a["style"] = "background-color: lightyellow"; // Add some text to the link // (This Add() function comes from libXMLTree, // see that library's documentation for more info) // This function will add a text node to the given // element Add(&a, "www.buhbird.com"); // All Element's have the operator<< overloaded // So, to output, all you have to do is this: cout << a << endl; return 0; } |
// Example #4: // Create an anchor element, add some attributes // and replace the text with an image #include <EmptyElement.h> #include <libXMLTree.h> // So we don't have to keep prefixing // libXMLTree:: to it's functions using namespace libXMLTree; int main() { // Create a new Element with the name "a" Element a("a"); // Add an href, a title, and even some style a["href"] = "http://www.buhbird.com"; a["title"] = "Click here for my homepage"; a["style"] = "background-color: lightyellow"; // This function will add a text node to the given // element Add(&a, "www.buhbird.com"); // I changed my mind, instead of the text, // I want a picture // So, let's first create the img element // Remeber it is and Empty Element <img/> EmptyElement img("img"); // Give it some attributes img["width"] = "71"; img["height"] = "33"; img["alt"] = "http://www.buhbird.com"; img["src"] = "http://www.buhbird.com/~kevin/docs/examples/link.png"; img["border"] = "0"; // So, let's delete the text // (Delete() is also in libXMLTree) Delete(&a, "www.buhbird.com"); // And add the image instead Add(&a, &img); // All Element's have the operator<< overloaded // So, to output, all you have to do is this: cout << a << endl; return 0; } |