Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

makeXmlForDoc.cxx File Reference

#include "xml/XmlParser.h"
#include "xml/Dom.h"
#include "xmlUtil/Source.h"
#include "xmlUtil/Arith.h"
#include "xmlUtil/Constants.h"
#include <dom/DOM_Element.hpp>
#include <dom/DOM_NodeList.hpp>
#include <dom/DOM_DocumentType.hpp>
#include <string>
#include <iostream>
#include <fstream>

Go to the source code of this file.

Functions

std::ostream * openOut (char *outfile)
void outProlog (const DOM_DocumentType &doctype, std::ostream &out)
char * stripDollar (char *toStrip)
const std::string dquote (&chDoubleQ[0])
const std::string myId ("$Id:makeXmlForDoc.cxx, v 1.5 2002/04/05 18:25:18 jrb Exp$")
const std::string idTemplate ("#Id:not committed$")
int main (int argc, char *argv[])

Variables

const char chDoubleQ [2] = {0x22, 0x0}


Function Documentation

const std::string dquote   chDoubleQ[0]
 

Referenced by outProlog().

const std::string idTemplate "#Id:not committed$"   
 

Referenced by main().

int main int    argc,
char *    argv[]
 

Main program for the forDoc application.

Parameters:
arg1  is the input xml file
arg2  is specification for the output file, or "-" to output to std::cout

Definition at line 50 of file makeXmlForDoc.cxx.

References xmlUtil::Source::add(), xmlUtil::Constants::evalConstants(), idTemplate(), myId(), openOut(), outProlog(), and xmlUtil::Constants::pruneConstants().

00050                                  {
00051 
00052   std::ostream *out;
00053   if (argc < 3) {  // instructions
00054     std::cout << "Required first argument is xml file to be parsed" 
00055               << std::endl;
00056     std::cout << "Required second argument is output file (- for stdout)"
00057               << std::endl;
00058     exit(0);
00059   }
00060 
00061   xml::XmlParser* parser = new xml::XmlParser();
00062   DOM_Document doc = parser->parse(argv[1]);
00063 
00064   if (doc == 0) {
00065     std::cout << "Document failed to parse correctly" << std::endl;
00066     exit(0);
00067   }
00068 
00069   // Else successful.   Open output
00070   out = openOut(argv[2]);
00071 
00072   DOM_Element docElt = doc.getDocumentElement();
00073   DOM_DocumentType  doctype = doc.getDoctype(); //  check for gdd?? 
00074 
00075   // For each const child of a derCategory
00076   //   evaluate it, saving value
00077   //   delete all children except <notes>
00078   xmlUtil::Constants *constants = new xmlUtil::Constants(doc);
00079   constants->evalConstants();
00080   constants->pruneConstants(true);  
00081 
00082   // Delete any id dictionaries
00083   DOM_NodeList dicts = docElt.getElementsByTagName(DOMString("idDict"));
00084   //  DOM_Node dictNode = dicts.item(0);
00085 
00086   unsigned nDict = dicts.getLength();
00087   for (unsigned iDict = 0; iDict < nDict; iDict++) {
00088     DOM_Node dictNode = dicts.item(iDict);
00089     DOM_Element& dictElt = static_cast<DOM_Element &> (dictNode);
00090 
00091     xml::Dom::prune(dictElt);
00092     (dictElt.getParentNode()).removeChild(dictElt);
00093   }
00094 
00095   // Delete all sections
00096   DOM_NodeList sections = docElt.getElementsByTagName(DOMString("section"));
00097   unsigned nSec = sections.getLength();
00098   for (unsigned iSec = 0; iSec < nSec; iSec++) {
00099     DOM_Node secNode = sections.item(iSec);
00100     DOM_Element& secElt = static_cast<DOM_Element &> (secNode);
00101     xml::Dom::prune(secElt);
00102     (secElt.getParentNode()).removeChild(secElt);
00103     //    secNode = toCome;
00104   }
00105 
00106 
00107   // Add a <source> child to the outer gdd element
00108   xmlUtil::Source * source = 
00109     new xmlUtil::Source(doc, "xmlUtil/v1/src/forDoc.exe", myId.c_str());
00110   source->add();
00111   
00112   // Output the xml declaration and all the text in the DOCTYPE (see DOMPrint)
00113   outProlog(doctype, *out);
00114 
00115   // If have gdd element with CVSid attribute, null it out.  Don't have
00116   // a real CVS id until the file has been committed
00117   if (docElt.getAttribute("CVSid") != DOMString() ) {
00118     std::string noId(idTemplate);
00119     noId.replace(0, 1, "$");
00120     docElt.setAttribute("CVSid", noId.c_str());
00121   }
00122   // Finally output the elements
00123   // May want option to exclude comments here
00124   xml::Dom::prettyPrintElement(docElt, *out, "");
00125 
00126   delete parser;
00127   return(0);
00128 }

const std::string myId "$Id:makeXmlForDoc.    cxx,
v 1.5 2002/04/05 18:25:18 jrb Exp$"   
 

Referenced by main().

std::ostream* openOut char *    outfile
 

Open specified output file (may be standard output if "-" is given as input argument)

Definition at line 134 of file makeXmlForDoc.cxx.

00135 {
00136   char  *hyphen = "-";
00137   std::ostream* out;
00138   
00139   if (*outfile == *hyphen) {
00140     out = &std::cout;
00141   }
00142   else {   // try to open file as ostream
00143     out = new std::ofstream(outfile);
00144   }
00145   return out;
00146 }

void outProlog const DOM_DocumentType &    doctype,
std::ostream &    out
 

Write out an xml declaration and copy the input DOCTYPE declaration to the output

Definition at line 152 of file makeXmlForDoc.cxx.

References dquote().

00152                                                                  {
00153   // write the xml declaration: <?xml version="1.0" ?>
00154 
00155   out << "<?xml version=" << dquote << "1.0" << dquote << "?>" << std::endl;
00156   if (doctype != DOM_DocumentType()) {
00157 
00158     out << "<!DOCTYPE " << xml::Dom::transToChar(doctype.getName()) << " ";
00159 
00160     DOMString id = doctype.getPublicId();
00161     if (id != 0)   {
00162       out << " PUBLIC " << dquote << xml::Dom::transToChar(id) << dquote;
00163       id = doctype.getSystemId();
00164       if (id != 0) {
00165         out << " " << dquote << xml::Dom::transToChar(id) << dquote;
00166       }
00167     }
00168     else {
00169       id = doctype.getSystemId();
00170       if (id != 0)   {
00171         out << " SYSTEM " << dquote << xml::Dom::transToChar(id) << dquote;
00172       }
00173     }
00174     id = doctype.getInternalSubset(); 
00175     if (id !=0) {
00176       out << "[" << xml::Dom::transToChar(id) << "]";
00177     }
00178     out << ">" << std::endl;
00179   }
00180 }

char* stripDollar char *    toStrip
 

Definition at line 11 of file Source.cxx.

00011                                     {
00012     const char dollar = '$';
00013     
00014     char   nothing = 0;
00015     unsigned len = strlen(toStrip);
00016     
00017     if (dollar == toStrip[len - 1]) {
00018       len--;
00019       toStrip[len] = nothing;
00020     }
00021     if (dollar == toStrip[0]) {
00022       return (toStrip + 1);
00023     }
00024     return toStrip;
00025   }


Variable Documentation

const char chDoubleQ[2] = {0x22, 0x0}
 

Definition at line 38 of file makeXmlForDoc.cxx.


Generated on Wed Oct 16 14:02:48 2002 by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001