[sword-devel] Why You Should Love SWORD 102 - XML Basics

Troy A. Griffitts scribe at crosswire.org
Thu Dec 2 08:56:21 MST 2010


XMLTag is a wonderful class for working with.... XML Tags!


For example.  If you have the tag:

<verse osisID="John.1.1" type='test type' yeah = "stuff" />

You can do handy things like:

cout << tag.getAttribute("type");
$ test type

tag.setAttribute("type", "changedType");
tag.setAttribute("subtype", "newSubtype");

cout << tag.getName();
$ verse

cout << tag.isEmpty();
$ true

cout << tag.isEndTag();
$ false

cout << XMLTag("</verse>").isEndTag();
$ true

cout << tag.toString();
$ <verse osisID="John.1.1" subtype="newSubtype" type="changedType"
yeah="stuff"/>

___________________

XMLTag even helps you parse list attributes like:

<reference osisRef="John.3.16 John.3.22-25 Act.4.12">

int count = tag.getAttributePartCount("osisRef", ' ');
for (int i = 0; i < count; ++i) {
    cout << x.getAttribute("osisRef", i, ' ');
}
$ John.3.16
$ John.3.22-25
$ Acts.4.12

___________________

And it mostly figures things out for you, even when the XML isn't
exactly valid (which we quite often find in imported modules)

For a wild and crazy show see:

http://crosswire.org/svn/sword/trunk/tests/xmltest.cpp




More information about the sword-devel mailing list