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 // -- Destructor
14 //
16 //
17 // -- Initialize XML
18 //
21 
22  unique_ptr<DOMImplementation> domImpl(DOMImplementationRegistry::getDOMImplementation(qtxml::_toDOMS("Range")));
23  if (domImpl == nullptr)
24  return false;
25  theDomWriter = domImpl->createLSSerializer();
26  if (theDomWriter == nullptr)
27  return false;
28  if (theDomWriter->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
29  theDomWriter->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
30  theDoc = domImpl->createDocument(nullptr, qtxml::_toDOMS(main), nullptr);
31  if (theDoc == nullptr)
32  return false;
33  theTopElement = theDoc->getDocumentElement();
34  theOutput = domImpl->createLSOutput();
35  if (theOutput == nullptr)
36  return false;
37  return true;
38 }
39 //
40 // -- Add an Element to the top node
41 //
43  theTopElement->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
44  theLastElement = theDoc->createElement(qtxml::_toDOMS(tag));
45  theTopElement->appendChild(theLastElement);
46 }
47 //
48 // -- Add an Element to the top node
49 //
51  theTopElement->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
52  theLastElement = theDoc->createElement(qtxml::_toDOMS(tag));
53  theLastElement->setAttribute(qtxml::_toDOMS("name"), qtxml::_toDOMS(name));
54  theTopElement->appendChild(theLastElement);
55 }
56 //
57 // -- Add a child to the last element
58 //
60  theLastElement->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
61  DOMElement* newElement = theDoc->createElement(qtxml::_toDOMS(tag));
62  newElement->setAttribute(qtxml::_toDOMS("name"), qtxml::_toDOMS(name));
63  theLastElement->appendChild(newElement);
64 }
65 //
66 // -- Add a child to the last element
67 //
70  std::string att_name,
71  std::string att_val) {
72  theLastElement->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
73  DOMElement* newElement = theDoc->createElement(qtxml::_toDOMS(tag));
74  newElement->setAttribute(qtxml::_toDOMS("name"), qtxml::_toDOMS(name));
75  newElement->setAttribute(qtxml::_toDOMS(att_name), qtxml::_toDOMS(att_val));
76 
77  theLastElement->appendChild(newElement);
78 }
79 //
80 // -- Add a child to the last element
81 //
84  std::string att_name1,
85  std::string att_val1,
86  std::string att_name2,
87  std::string att_val2) {
88  theLastElement->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
89  DOMElement* newElement = theDoc->createElement(qtxml::_toDOMS(tag));
90  newElement->setAttribute(qtxml::_toDOMS("name"), qtxml::_toDOMS(name));
91  newElement->setAttribute(qtxml::_toDOMS(att_name1), qtxml::_toDOMS(att_val1));
92  newElement->setAttribute(qtxml::_toDOMS(att_name2), qtxml::_toDOMS(att_val2));
93  theLastElement->appendChild(newElement);
94 }
95 //
96 // -- Add a child to the last element
97 //
100  std::string att_name1,
101  std::string att_val1,
102  std::string att_name2,
103  std::string att_val2,
104  std::string att_name3,
105  std::string att_val3) {
106  theLastElement->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
107  DOMElement* newElement = theDoc->createElement(qtxml::_toDOMS(tag));
108  newElement->setAttribute(qtxml::_toDOMS("name"), qtxml::_toDOMS(name));
109  newElement->setAttribute(qtxml::_toDOMS(att_name1), qtxml::_toDOMS(att_val1));
110  newElement->setAttribute(qtxml::_toDOMS(att_name2), qtxml::_toDOMS(att_val2));
111  newElement->setAttribute(qtxml::_toDOMS(att_name3), qtxml::_toDOMS(att_val3));
112  theLastElement->appendChild(newElement);
113 }
114 //
115 // -- Write to File
116 //
118  XMLFormatTarget* formTarget = new LocalFileFormatTarget(fname.c_str());
119  theOutput->setByteStream(formTarget);
120  theDomWriter->write(theTopElement, theOutput);
121  delete formTarget;
122  theOutput->release();
123  theDoc->release();
124  theDomWriter->release();
125 }
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