1 /**********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 ***********************************************************************/
15 #include <fc_config.h>
18 #ifdef FREECIV_HAVE_XML_REGISTRY
20 #include <libxml/parser.h>
23 #include "capability.h"
27 #include "section_file.h"
29 #include "registry_xml.h"
31 /**************************************************************************
32 Load section file from xml-file
33 **************************************************************************/
34 struct section_file
*xmlfile_load(xmlDoc
*sec_doc
, const char *filename
)
36 struct section_file
*secfile
;
41 secfile
= secfile_new(TRUE
);
43 xmlroot
= xmlDocGetRootElement(sec_doc
);
44 if (xmlroot
== NULL
|| strcmp((const char *)xmlroot
->name
, "Freeciv")) {
45 /* TRANS: do not translate <Freeciv> */
46 log_error(_("XML-file has no root node <Freeciv>"));
47 secfile_destroy(secfile
);
51 cap
= (char *)xmlGetNsProp(xmlroot
, (xmlChar
*)"options", NULL
);
54 log_error(_("XML-file has no capabilities defined!"));
55 secfile_destroy(secfile
);
59 if (!has_capabilities(FCXML_CAPSTR
, cap
)) {
60 log_error(_("XML-file has incompatible capabilities."));
61 log_normal(_("Freeciv capabilities: %s"), FCXML_CAPSTR
);
62 log_normal(_("File capabilities: %s"), cap
);
63 secfile_destroy(secfile
);
69 secfile
->name
= fc_strdup(filename
);
74 current
= xmlroot
->children
;
76 while (current
!= NULL
) {
77 if (current
->type
== XML_ELEMENT_NODE
) {
78 struct section
*psection
;
81 psection
= secfile_section_new(secfile
, (const char *)current
->name
);
82 sec_node
= current
->children
;
84 while (sec_node
!= NULL
) {
85 if (sec_node
->type
== XML_ELEMENT_NODE
) {
86 xmlNodePtr value_node
= sec_node
->children
;
88 while (value_node
!= NULL
) {
89 if (value_node
->type
== XML_TEXT_NODE
) {
90 const char *content
= (const char *) xmlNodeGetContent(value_node
);
91 int len
= strlen(content
);
94 strncpy(buf
, content
, sizeof(buf
));
95 if (buf
[0] == '"' && buf
[len
- 1] == '"') {
99 if (!entry_from_token(psection
, (const char *) sec_node
->name
,
101 log_error("Cannot parse token \"%s\"", content
);
102 secfile_destroy(secfile
);
107 value_node
= value_node
->next
;
111 sec_node
= sec_node
->next
;
115 current
= current
->next
;
121 #endif /* FREECIV_HAVE_XML_REGISTRY */