CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripConfigWriter.cc
Go to the documentation of this file.
2 
3 
5 
6 //
7 // -- Constructor
8 //
10 }
11 //
12 // -- Destructor
13 //
15 
16 }
17 //
18 // -- Initialize XML
19 //
20 bool SiStripConfigWriter::init(std::string main) {
21  xercesc::XMLPlatformUtils::Initialize();
22 
23  xercesc::DOMImplementation* domImpl = xercesc::DOMImplementationRegistry::getDOMImplementation(qtxml::_toDOMS("Range"));
24  if (!domImpl) return false;
25  domWriter = (dynamic_cast<xercesc::DOMImplementation*>(domImpl))->createDOMWriter();
26  if (!domWriter) return false;
27  domWriter->canSetFeature(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint, true);
28  theDoc = domImpl->createDocument(0,qtxml::_toDOMS(main), 0);
29  if (!theDoc) return false;
30  theTopElement = theDoc->getDocumentElement();
31  return true;
32 }
33 //
34 // -- Add an Element to the top node
35 //
37  theTopElement->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
38  lastElement = theDoc->createElement(qtxml::_toDOMS(tag));
39  theTopElement->appendChild(lastElement);
40 }
41 //
42 // -- Add an Element to the top node
43 //
44 void SiStripConfigWriter::createElement(std::string tag, std::string name) {
45  theTopElement->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
46  lastElement = theDoc->createElement(qtxml::_toDOMS(tag));
47  lastElement->setAttribute(qtxml::_toDOMS("name"), qtxml::_toDOMS(name));
48  theTopElement->appendChild(lastElement);
49 }
50 //
51 // -- Add a child to the last element
52 //
53 void SiStripConfigWriter::createChildElement(std::string tag, std::string name) {
54 
55  lastElement->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
56  xercesc::DOMElement* newElement = theDoc->createElement(qtxml::_toDOMS(tag));
57  newElement->setAttribute(qtxml::_toDOMS("name"), qtxml::_toDOMS(name));
58  lastElement->appendChild(newElement);
59 }
60 //
61 // -- Add a child to the last element
62 //
63 void SiStripConfigWriter::createChildElement(std::string tag, std::string name, std::string att_name, std::string att_val) {
64 
65  lastElement->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
66  xercesc::DOMElement* newElement = theDoc->createElement(qtxml::_toDOMS(tag));
67  newElement->setAttribute(qtxml::_toDOMS("name"), qtxml::_toDOMS(name));
68  newElement->setAttribute(qtxml::_toDOMS(att_name), qtxml::_toDOMS(att_val));
69 
70  lastElement->appendChild(newElement);
71 
72 }
73 //
74 // -- Add a child to the last element
75 //
76 void SiStripConfigWriter::createChildElement(std::string tag,std::string name,std::string att_name1, std::string att_val1,
77  std::string att_name2, std::string att_val2) {
78  lastElement->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
79  xercesc::DOMElement* newElement = theDoc->createElement(qtxml::_toDOMS(tag));
80  newElement->setAttribute(qtxml::_toDOMS("name"), qtxml::_toDOMS(name));
81  newElement->setAttribute(qtxml::_toDOMS(att_name1), qtxml::_toDOMS(att_val1));
82  newElement->setAttribute(qtxml::_toDOMS(att_name2), qtxml::_toDOMS(att_val2));
83  lastElement->appendChild(newElement);
84 
85 }
86 //
87 // -- Add a child to the last element
88 //
89 void SiStripConfigWriter::createChildElement(std::string tag,std::string name,std::string att_name1, std::string att_val1,
90  std::string att_name2, std::string att_val2,
91  std::string att_name3, std::string att_val3) {
92 
93  lastElement->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
94  xercesc::DOMElement* newElement = theDoc->createElement(qtxml::_toDOMS(tag));
95  newElement->setAttribute(qtxml::_toDOMS("name"), qtxml::_toDOMS(name));
96  newElement->setAttribute(qtxml::_toDOMS(att_name1), qtxml::_toDOMS(att_val1));
97  newElement->setAttribute(qtxml::_toDOMS(att_name2), qtxml::_toDOMS(att_val2));
98  newElement->setAttribute(qtxml::_toDOMS(att_name3), qtxml::_toDOMS(att_val3));
99  lastElement->appendChild(newElement);
100 
101 }
102 //
103 // -- Write to File
104 //
106  xercesc::XMLFormatTarget* formTarget = new xercesc::LocalFileFormatTarget(fname.c_str());
107  domWriter->writeNode(formTarget, *theTopElement);
108  delete formTarget;
109  theDoc->release();
110 }
void createChildElement(std::string tag, std::string name)
xercesc::DOMElement * lastElement
int main(int argc, char **argv)
void createElement(std::string tag)
bool init(std::string main)
Write XML file.
~SiStripConfigWriter()
Destructor.
xercesc::DOMWriter * domWriter
xercesc::DOMImplementation * domImpl
XMLCh * _toDOMS(std::string temp)
string fname
main script
void write(std::string fname)
xercesc::DOMElement * theTopElement
xercesc::DOMDocument * theDoc