Tutorials:SWORD 102

From CrossWire Bible Society
Revision as of 12:22, 10 August 2012 by David Haslam (talk | contribs) (XML Basics: Category:Tutorials)

Jump to: navigation, search

XML Basics

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"

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 the link below: