XML/Input: Difference between revisions

No edit summary
Line 214:
 
=={{header|C++}}==
<lang c++>#include <string>
/*
Using the Qt library's XML parser.
*/
#include <iostream>
 
#include <QDomDocument>
int main( ) {
#include <QObject>
const std::string input( "<Students>\n"
"<Student Name=\"April\" Gender=\"F\" DateOfBirth=\"1989-01-02\" />\n"
"<Student Name=\"Bob\" Gender=\"M\" DateOfBirth=\"1990-03-04\" />\n"
"<Student Name=\"Chad\" Gender=\"M\" DateOfBirth=\"1991-05-06\" />\n"
"<Student Name=\"Dave\" Gender=\"M\" DateOfBirth=\"1992-07-08\">\n"
"<Pet Type=\"dog\" Name=\"Rover\" />\n"
"</Student>\n"
"<Student DateOfBirth=\"1993-09-10\" Gender=\"F\" Name=\"&#x00C9;mily\" />\n"
"</Students>") ;
std::string::size_type ende = 0 ;
std::string::size_type found = input.find( "<Student" , 0 ) ;
while ( found != std::string::npos ) {
found = input.find( "Name" , found + 7 ) ;
ende = input.find( "\"" , found + 7 ) ;
if ( ende != std::string::npos )
std::cout << input.substr( found + 6 , ende - ( found + 6 ) ) <<
'\n' ;
found = input.find( "<Student" , ende + 1 ) ;
}
return 0 ;
}</lang>
 
int main( ) {
QDomDocument doc;
 
doc.setContent(
QObject::tr(
const std::string input( "<Students>\n"
"<Student Name=\"April\" Gender=\"F\" DateOfBirth=\"1989-01-02\" />\n"
"<Student Name=\"Bob\" Gender=\"M\" DateOfBirth=\"1990-03-04\" />\n"
"<Student Name=\"Chad\" Gender=\"M\" DateOfBirth=\"1991-05-06\" />\n"
"<Student Name=\"Dave\" Gender=\"M\" DateOfBirth=\"1992-07-08\">\n"
"<Pet Type=\"dog\" Name=\"Rover\" />\n"
"</Student>\n"
"<Student DateOfBirth=\"1993-09-10\" Gender=\"F\" Name=\"&#x00C9;mily\" />\n"
"</Students>") );
QDomElement n = doc.documentElement().firstChildElement("Student");
while(!n.isNull()) {
std::cout << qPrintable(n.attribute("Name")) << std::endl;
n = n.nextSiblingElement();
}
'\n'return 0;
}
}</lang>
 
=={{header|Common Lisp}}==
Anonymous user