Difference between revisions of "Tutorials:SWORD 102"

From CrossWire Bible Society
Jump to: navigation, search
(Copied from email, lightly edited)
 
m
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
== XML Basics ==
 
== XML Basics ==
<pre>
+
 
  
 
XMLTag is a wonderful class for working with.... XML Tags!
 
XMLTag is a wonderful class for working with.... XML Tags!
Line 10: Line 10:
 
You can do handy things like:
 
You can do handy things like:
  
cout << tag.getAttribute("type");
+
<pre>cout << tag.getAttribute("type");
 
$ test type
 
$ test type
  
Line 31: Line 31:
 
$ <verse osisID="John.1.1" subtype="newSubtype" type="changedType"
 
$ <verse osisID="John.1.1" subtype="newSubtype" type="changedType"
 
yeah="stuff"/>
 
yeah="stuff"/>
 
+
</pre>
___________________
+
<hr/>
  
 
XMLTag even helps you parse list attributes like:
 
XMLTag even helps you parse list attributes like:
Line 38: Line 38:
 
<reference osisRef="John.3.16 John.3.22-25 Act.4.12">
 
<reference osisRef="John.3.16 John.3.22-25 Act.4.12">
  
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 << x.getAttribute("osisRef", i, ' ');
+
     cout << tag.getAttribute("osisRef", i, ' ');
 
}
 
}
 
$ John.3.16
 
$ John.3.16
 
$ John.3.22-25
 
$ John.3.22-25
 
$ Acts.4.12
 
$ Acts.4.12
 
+
</pre>
___________________
+
<hr>
  
 
And it mostly figures things out for you, even when the XML isn't
 
And it mostly figures things out for you, even when the XML isn't
Line 52: Line 52:
  
 
For a wild and crazy show see the link below:
 
For a wild and crazy show see the link below:
</pre>
+
 
  
 
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:


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