CMS 3D CMS Logo

SiStripConfigWriter.cc
Go to the documentation of this file.
3 #include <memory>
4 
5 using namespace std;
6 using namespace xercesc;
7 
8 //
9 // -- Constructor
10 //
12 }
13 //
14 // -- Destructor
15 //
17 }
18 //
19 // -- Initialize XML
20 //
23 
24  unique_ptr<DOMImplementation> domImpl( DOMImplementationRegistry::getDOMImplementation(qtxml::_toDOMS("Range")));
25  if( domImpl == nullptr ) return false;
26  theDomWriter = domImpl->createLSSerializer();
27  if( theDomWriter == nullptr ) return false;
28  if( theDomWriter->getDomConfig()->canSetParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true ))
29  theDomWriter->getDomConfig()->setParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true );
30  theDoc = domImpl->createDocument( 0, qtxml::_toDOMS(main), 0 );
31  if( theDoc == nullptr ) return false;
32  theTopElement = theDoc->getDocumentElement();
33  theOutput = domImpl->createLSOutput();
34  if( theOutput == nullptr ) return false;
35  return true;
36 }
37 //
38 // -- Add an Element to the top node
39 //
41  theTopElement->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
42  theLastElement = theDoc->createElement(qtxml::_toDOMS(tag));
43  theTopElement->appendChild(theLastElement);
44 }
45 //
46 // -- Add an Element to the top node
47 //
49  theTopElement->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
50  theLastElement = theDoc->createElement(qtxml::_toDOMS(tag));
51  theLastElement->setAttribute(qtxml::_toDOMS("name"), qtxml::_toDOMS(name));
52  theTopElement->appendChild(theLastElement);
53 }
54 //
55 // -- Add a child to the last element
56 //
58 
59  theLastElement->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
60  DOMElement* newElement = theDoc->createElement(qtxml::_toDOMS(tag));
61  newElement->setAttribute(qtxml::_toDOMS("name"), qtxml::_toDOMS(name));
62  theLastElement->appendChild(newElement);
63 }
64 //
65 // -- Add a child to the last element
66 //
68 
69  theLastElement->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
70  DOMElement* newElement = theDoc->createElement(qtxml::_toDOMS(tag));
71  newElement->setAttribute(qtxml::_toDOMS("name"), qtxml::_toDOMS(name));
72  newElement->setAttribute(qtxml::_toDOMS(att_name), qtxml::_toDOMS(att_val));
73 
74  theLastElement->appendChild(newElement);
75 
76 }
77 //
78 // -- Add a child to the last element
79 //
81  std::string att_name2, std::string att_val2) {
82  theLastElement->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
83  DOMElement* newElement = theDoc->createElement(qtxml::_toDOMS(tag));
84  newElement->setAttribute(qtxml::_toDOMS("name"), qtxml::_toDOMS(name));
85  newElement->setAttribute(qtxml::_toDOMS(att_name1), qtxml::_toDOMS(att_val1));
86  newElement->setAttribute(qtxml::_toDOMS(att_name2), qtxml::_toDOMS(att_val2));
87  theLastElement->appendChild(newElement);
88 
89 }
90 //
91 // -- Add a child to the last element
92 //
94  std::string att_name2, std::string att_val2,
95  std::string att_name3, std::string att_val3) {
96 
97  theLastElement->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
98  DOMElement* newElement = theDoc->createElement(qtxml::_toDOMS(tag));
99  newElement->setAttribute(qtxml::_toDOMS("name"), qtxml::_toDOMS(name));
100  newElement->setAttribute(qtxml::_toDOMS(att_name1), qtxml::_toDOMS(att_val1));
101  newElement->setAttribute(qtxml::_toDOMS(att_name2), qtxml::_toDOMS(att_val2));
102  newElement->setAttribute(qtxml::_toDOMS(att_name3), qtxml::_toDOMS(att_val3));
103  theLastElement->appendChild(newElement);
104 
105 }
106 //
107 // -- Write to File
108 //
110  XMLFormatTarget* formTarget = new LocalFileFormatTarget(fname.c_str());
111  theOutput->setByteStream(formTarget);
112  theDomWriter->write(theTopElement, theOutput);
113  delete formTarget;
114  theOutput->release();
115  theDoc->release();
116  theDomWriter->release();
117 }
void createChildElement(std::string tag, std::string name)
void xercesInitialize()
Definition: Xerces.cc:18
void createElement(std::string tag)
bool init(std::string main)
Write XML file.
~SiStripConfigWriter()
Destructor.
XMLCh * _toDOMS(std::string temp)
string fname
main script
void write(std::string fname)
Definition: main.py:1