dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #24433
Reading nested XML dataset
I need some advice on how to implement the XML parsing for
MeshDomains. I have this:
<mesh>
<domains dim="3">
<mesh_value_collection type="uint" dim="0" />
stuff
</mesh_value_collection>
<mesh_value_collection type="uint" dim="1" />
stuff
</mesh_value_collection>
<mesh_value_collection type="uint" dim="2" />
stuff
</mesh_value_collection>
</domains>
</mesh>
The parsing of MeshValueCollection is implemented in
XMLMeshValueCollection.cpp and I want to reuse that inside
XMLMesh.cpp.
So I've tried something like this:
// Check if we have any domains
const pugi::xml_node xml_domains = mesh_node.child("domains");
if (!xml_domains)
return;
// Iterate over data
for (pugi::xml_node_iterator it = xml_domains.begin();
it != xml_domains.end(); ++it)
{
// Check that node is <mesh_value_collection>
const std::string node_name = it->name();
if (node_name != "mesh_value_collection")
error("Expecting XML node <mesh_value_collection> but got
<%s>.",
node_name.c_str());
// Get attributes
const std::string type = it->attribute("type").value();
const uint dim = it->attribute("dim").as_uint();
// Check that the type is uint
if (type != "uint")
{
dolfin_error("XMLMesh.cpp",
"read DOLFIN mesh from XML file",
"Mesh domains must be marked as uint, not %s",
type.c_str());
}
// Read MeshValueCollection
XMLMeshValueCollection::read(domains.markers(dim), type, *it);
}
The problem here is that the node *it sent to XMLMeshValueCollection
is already the node for the MeshValueCollection but that parser
expects to get the parent node. But I can't really send it the parent
node since the parent may have more than one child.
Any ideas?
--
Anders
Follow ups