Difference between revisions of "Tutorials:SWORD 102"
From CrossWire Bible Society
m |
|||
(One intermediate revision by one other user not shown) | |||
Line 40: | Line 40: | ||
<pre>int count = tag.getAttributePartCount("osisRef", ' '); | <pre>int count = tag.getAttributePartCount("osisRef", ' '); | ||
for (int i = 0; i < count; ++i) { | for (int i = 0; i < count; ++i) { | ||
− | cout << | + | cout << tag.getAttribute("osisRef", i, ' '); |
} | } | ||
$ John.3.16 | $ John.3.16 | ||
Line 55: | Line 55: | ||
http://crosswire.org/svn/sword/trunk/tests/xmltest.cpp | http://crosswire.org/svn/sword/trunk/tests/xmltest.cpp | ||
+ | |||
+ | [[Category:Tutorials]] |
Latest revision as of 00:00, 3 March 2018
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" 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 << tag.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: