All Classes Files Functions Variables Enumerations Enumerator Macros
xml.cpp
Go to the documentation of this file.
1 #include "output.hpp"
10 
17 // Outputs summary information from objects in XML format
18 void OutPut::outputXML( Library *libObj, ostream &tout )
19 {
20  // Check if Library objects don't exist
21  if( libObj == NULL )
22  {
23  // Write to the standard console output
24  cout << "Error: no data found in Parser object" << endl;
25  }
26  // Library objects exist
27  else
28  {
29  tout << "<?xml version=\"1.0\"?>" << endl
30  << "<CLERK_REPORT>" << endl;
31 
32  // For each show
33  for( unsigned int i = 0; i < libObj->shows.size(); i++ )
34  {
35 
36  tout << " <SHOW>" << endl
37  << " <SHOWNAME>" << libObj->shows[i].getShowname() << "</SHOWNAME>" << endl;
38 
39  // For each season
40  for( unsigned int j = 0; j < libObj->shows[i].seasons.size(); j++ )
41  {
42  // For each episode
43  for( unsigned int k = 0; k < libObj->shows[i].seasons[j].episodes.size(); k++ )
44  {
45  tout << " <FILE>" << endl
46  << " <SEASON>" << libObj->shows[i].seasons[j].getNumber() << "</SEASON>" << endl
47  << " <EPISODE>" << libObj->shows[i].seasons[j].episodes[k].getNumber();
48 
49  // Check if extra episodes exist
50  if( libObj->shows[i].seasons[j].episodes[k].getExtra() > 0 )
51  {
52  tout << libObj->shows[i].seasons[j].episodes[k].getExtra();
53  }
54 
55  // Check if partial episodes exist
56  if( libObj->shows[i].seasons[j].episodes[k].getPart() != "" )
57  {
58  tout << libObj->shows[i].seasons[j].episodes[k].getPart();
59  }
60 
61  tout << "</EPISODE>" << endl
62  << " <TITLE>" << xmlParse( libObj->shows[i].seasons[j].episodes[k].getTitle() ) << "</TITLE>" << endl
63  << " <LOCATION>" << libObj->shows[i].seasons[j].episodes[k].getOldDir() << "</LOCATION>" << endl
64  << " <FILENAME>" << xmlParse( libObj->shows[i].seasons[j].episodes[k].getOldFile() ) << "</FILENAME>" << endl
65  << " </FILE>" << endl;
66  }
67  }
68 
69  tout << " </SHOW>" << endl;
70  }
71 
72  tout << "</CLERK_REPORT>" << endl;
73  }
74 };
75 
79 // Replace & with xml &amp;
80 string OutPut::xmlParse( string xmlString )
81 {
82  string xmlAmp = "amp;";
83  unsigned int xmlPos = xmlString.find( "&" );
84 
85  while( xmlPos < xmlString.length() )
86  {
87  xmlString.insert( xmlPos+1, xmlAmp );
88  xmlPos = xmlString.find( "&", xmlPos+1 );
89  }
90 
91  return xmlString;
92 }
The OutPut class prints summary and error information from objects.
static string xmlParse(string)
Replaces "&" with xml "&amp;" in a given string.
Definition: xml.cpp:80
vector< Show > shows
A vector that holds each Show.
Definition: library.hpp:41
static void outputXML(Library *, ostream &)
Outputs summary information from objects in XML format.
Definition: xml.cpp:18
Stores all info required to describe all shows.
Definition: library.hpp:30