32 error_show(
"No file names found!", __FILE__, __LINE__);
50 xmlNodePtr comment_node;
51 xmlNodePtr model_node;
55 cout <<
"DEBUG read_xml: XML filenames: " << endl;
56 for ( thisfile = file_list; thisfile; thisfile = thisfile->
next )
57 cout <<
" " << *thisfile;
61 for ( thisfile = file_list; thisfile; thisfile = thisfile->
next ) {
63 doc = xmlParseFile(thisfile->
c_str());
64 if ( doc == NULL )
return NULL;
69 cout <<
"# Reading XML file: " << *thisfile << endl;
71 root_node = xmlDocGetRootElement(doc);
72 if ( root_node == NULL ) {
80 if ( xmlStrcmp(root_node->name, BAD_CAST
"model_file") ) {
81 cerr <<
"Error: The document " << *thisfile <<
" is not a model file!" << endl;
89 for ( comment_node = root_node->xmlChildrenNode; comment_node &&
90 xmlStrcmp(comment_node->name, BAD_CAST
COMMENT); comment_node = comment_node->next ) ;
92 for ( i=0, model_node = root_node->xmlChildrenNode; model_node; model_node = model_node->next )
93 if ( !xmlStrcmp(model_node->name, BAD_CAST
MODEL) ) {
95 id = (
char *) xmlGetProp(model_node, BAD_CAST
ID);
99 if ( !xmlStrcmp(model_node->name, BAD_CAST
COMMENT) )
100 mp->
comment = (
char *) xmlNodeGetContent(model_node);
101 else if ( comment_node )
102 mp->
comment = (
char *) xmlNodeGetContent(comment_node);
113 for ( node = model_node->xmlChildrenNode; node; node = node->next ) {
114 if ( !xmlStrcmp(node->name, BAD_CAST
COMPTYPE) ) {
115 id = (
char *) xmlGetProp(node, BAD_CAST
ID);
117 if ( !mp->
type ) mp->
type = comptype;
124 if ( !xmlStrcmp(node->name, BAD_CAST
COMPONENT) ) {
125 id = (
char *) xmlGetProp(node, BAD_CAST
ID);
148 for ( node = model_node->xmlChildrenNode; node; node = node->next ) {
149 if ( !xmlStrcmp(node->name, BAD_CAST
COMPLINK) ) {
151 for ( comp = mp->
comp; comp && comp->
id !=
id; comp = comp->
next ) ;
153 cerr <<
"Error: Component " <<
id <<
" not found! (1)" << endl;
155 for ( comp2 = mp->
comp; comp2 && comp2->
id !=
id; comp2 = comp2->
next ) ;
157 cerr <<
"Error: Component " <<
id <<
" not found! (2)" << endl;
158 link =
link_add(&link, comp, comp2, 1, 1);
170 for ( link=mp->
link; link; link=link->
next )
187 cerr <<
"Error: XML files are not supported!" << endl << endl;
199 #if defined(HAVE_XML)
204 xmlNodePtr comment_node;
205 xmlNodePtr model_node;
206 xmlNodePtr type_node;
207 xmlNodePtr comp_node;
208 xmlNodePtr link_node;
216 cout <<
"# Writing file: " << filename << endl;
218 xmlDocPtr doc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION);
220 cerr <<
"Error: The XML document tree was not created!" << endl;
224 xmlNodePtr root_node = xmlNewDocPI(doc, BAD_CAST
"xml-stylesheet",
225 BAD_CAST
"href=\"Bsoft_model.xsl\" type=\"text/xsl\"");
227 root_node = xmlNewNode(NULL, BAD_CAST
"model_file");
228 xmlDocSetRootElement(doc, root_node);
230 comment_node = xmlNewChild(root_node, NULL, BAD_CAST
COMMENT, NULL);
233 for ( i=1, mp =
model; mp; mp = mp->
next, i++ ) {
234 model_node = xmlNewChild(root_node, NULL, BAD_CAST
MODEL, NULL);
236 xmlNewProp(model_node, BAD_CAST
ID, BAD_CAST mp->
id.
c_str());
247 for ( comptype = mp->
type; comptype; comptype = comptype->
next ) {
248 type_node = xmlNewChild(model_node, NULL, BAD_CAST
COMPTYPE, NULL);
249 xmlNewProp(type_node, BAD_CAST
ID, BAD_CAST comptype->
id.
c_str());
256 for ( comp = mp->
comp; comp; comp = comp->
next ) {
257 comp_node = xmlNewChild(model_node, NULL, BAD_CAST
COMPONENT, NULL);
258 xmlNewProp(comp_node, BAD_CAST
ID, BAD_CAST comp->
id.
c_str());
276 for ( link = mp->
link; link; link = link->
next ) {
277 link_node = xmlNewChild(model_node, NULL, BAD_CAST
COMPLINK, NULL);
291 if ( err == 0 ) err = xmlSaveFormatFile(filename.
c_str(), doc, 1);
300 cerr <<
"Error: XML files are not supported!" << endl << endl;