]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
Minimize external dependencies: libxml2 is only needed locally for XAO package
authorvsr <vsr@opencascade.com>
Wed, 9 Oct 2013 08:56:05 +0000 (08:56 +0000)
committervsr <vsr@opencascade.com>
Wed, 9 Oct 2013 08:56:05 +0000 (08:56 +0000)
src/XAO/XAO_Xao.cxx
src/XAO/XAO_XaoExporter.cxx
src/XAO/XAO_XaoExporter.hxx

index 2bd64a3574657137f472e61c3140797ed7d241b4..c7608a2591c3f5879c98eec0464729e39099a128 100644 (file)
@@ -30,6 +30,8 @@
 #include "XAO_StringField.hxx"
 #include "XAO_XaoExporter.hxx"
 
 #include "XAO_StringField.hxx"
 #include "XAO_XaoExporter.hxx"
 
+#include <libxml/xmlstring.h>
+
 using namespace XAO;
 
 const xmlChar* C_XAO_VERSION = (xmlChar*)"1.0";
 using namespace XAO;
 
 const xmlChar* C_XAO_VERSION = (xmlChar*)"1.0";
index 414f118cebfb06f13fdbc50a61b839857a8f72a1..d41b1f74f31a875536458bac1f9b05fbc03a3ed2 100644 (file)
@@ -82,10 +82,41 @@ namespace XAO
 
 using namespace XAO;
 
 
 using namespace XAO;
 
-std::string XaoExporter::readStringProp(xmlNodePtr node, const xmlChar* attribute,
-        const bool& required, const std::string& defaultValue,
-        const std::string& exception /*= std::string() */)
-{
+namespace {
+    xmlDocPtr exportXMLDoc(Xao* xaoObject);
+    void exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePtr xao);
+    void exportGeometricElements(Geometry* xaoGeometry, xmlNodePtr topology,
+                                XAO::Dimension dim, const xmlChar* colTag, const xmlChar* eltTag);
+    void exportGroups(Xao* xaoObject, xmlNodePtr xao);
+    void exportFields(Xao* xaoObject, xmlNodePtr xao);
+    void exportStep(Step* step, Field* field, xmlNodePtr nodeSteps);
+
+    void parseXMLDoc(xmlDocPtr doc, Xao* xaoObject);
+    void parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode, Xao* xaoObject);
+    void parseGeometryNode(xmlDocPtr doc, xmlNodePtr geometryNode, Xao* xaoObject);
+    void parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode, Geometry* geometry);
+    void parseTopologyNode(xmlNodePtr topologyNode, Geometry* geometry);
+    void parseVerticesNode(xmlNodePtr verticesNode, Geometry* geometry);
+    void parseEdgesNode(xmlNodePtr edgesNode, Geometry* geometry);
+    void parseFacesNode(xmlNodePtr facesNode, Geometry* geometry);
+    void parseSolidsNode(xmlNodePtr solidsNode, Geometry* geometry);
+    void parseGroupsNode(xmlNodePtr groupsNode, Xao* xaoObject);
+    void parseGroupNode(xmlNodePtr groupNode, Xao* xaoObject);
+
+    void parseFieldsNode(xmlNodePtr fieldsNode, Xao* xaoObject);
+    void parseFieldNode(xmlNodePtr fieldNode, Xao* xaoObject);
+    void parseStepNode(xmlNodePtr stepNode, Field* field);
+    void parseStepElementNode(xmlNodePtr eltNode, Step* step);
+
+    std::string readStringProp(xmlNodePtr node, const xmlChar* attribute,
+                              const bool& required, const std::string& defaultValue, const std::string& exception = std::string(""));
+    int readIntegerProp(xmlNodePtr node, const xmlChar* attribute,
+                       const bool& required, const int& defaultValue, const std::string& exception = std::string(""));
+
+  std::string readStringProp(xmlNodePtr node, const xmlChar* attribute,
+                            const bool& required, const std::string& defaultValue,
+                            const std::string& exception /*= std::string() */)
+  {
     xmlChar* strAttr = xmlGetProp(node, attribute);
     if (strAttr == NULL)
     {
     xmlChar* strAttr = xmlGetProp(node, attribute);
     if (strAttr == NULL)
     {
@@ -104,12 +135,12 @@ std::string XaoExporter::readStringProp(xmlNodePtr node, const xmlChar* attribut
     std::string res = (char*)strAttr;
     xmlFree(strAttr);
     return res;
     std::string res = (char*)strAttr;
     xmlFree(strAttr);
     return res;
-}
+  }
 
 
-int XaoExporter::readIntegerProp(xmlNodePtr node, const xmlChar* attribute,
-        const bool& required, const int& defaultValue,
-        const std::string& exception /*= std::string() */)
-{
+  int readIntegerProp(xmlNodePtr node, const xmlChar* attribute,
+                     const bool& required, const int& defaultValue,
+                     const std::string& exception /*= std::string() */)
+  {
     xmlChar* strAttr = xmlGetProp(node, attribute);
     if (strAttr == NULL)
     {
     xmlChar* strAttr = xmlGetProp(node, attribute);
     if (strAttr == NULL)
     {
@@ -128,34 +159,10 @@ int XaoExporter::readIntegerProp(xmlNodePtr node, const xmlChar* attribute,
     int res = XaoUtils::stringToInt((char*)strAttr);
     xmlFree(strAttr);
     return res;
     int res = XaoUtils::stringToInt((char*)strAttr);
     xmlFree(strAttr);
     return res;
-}
-
-const bool XaoExporter::saveToFile(Xao* xaoObject, const std::string& fileName)
-throw (XAO_Exception)
-{
-    xmlDocPtr doc = exportXMLDoc(xaoObject);
-    xmlSaveFormatFileEnc(fileName.c_str(), doc, "UTF-8", 1); // format = 1 for node indentation
-    xmlFreeDoc(doc);
-
-    return true;
-}
-
-const std::string XaoExporter::saveToXml(Xao* xaoObject)
-throw (XAO_Exception)
-{
-    xmlDocPtr doc = exportXMLDoc(xaoObject);
+  }
 
 
-    xmlChar *xmlbuff;
-    int buffersize;
-    xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1); // format = 1 for node indentation
-    xmlFreeDoc(doc);
-    xmlCleanupGlobals();
-
-    return (char*)xmlbuff;
-}
-
-xmlDocPtr XaoExporter::exportXMLDoc(Xao* xaoObject)
-{
+  xmlDocPtr exportXMLDoc(Xao* xaoObject)
+  {
     // Creating the Xml document
     xmlDocPtr masterDocument = xmlNewDoc(BAD_CAST "1.0");
     xmlNodePtr xao = xmlNewNode(0, C_TAG_XAO);
     // Creating the Xml document
     xmlDocPtr masterDocument = xmlNewDoc(BAD_CAST "1.0");
     xmlNodePtr xao = xmlNewNode(0, C_TAG_XAO);
@@ -173,11 +180,11 @@ xmlDocPtr XaoExporter::exportXMLDoc(Xao* xaoObject)
     exportFields(xaoObject, xao);
 
     return masterDocument;
     exportFields(xaoObject, xao);
 
     return masterDocument;
-}
+  }
 
 
-void XaoExporter::exportGeometricElements(Geometry* xaoGeometry,
-        xmlNodePtr topology, XAO::Dimension dim, const xmlChar* colTag, const xmlChar* eltTag)
-{
+  void exportGeometricElements(Geometry* xaoGeometry,
+                              xmlNodePtr topology, XAO::Dimension dim, const xmlChar* colTag, const xmlChar* eltTag)
+  {
     xmlNodePtr vertices = xmlNewChild(topology, 0, colTag, 0);
     xmlNewProp(vertices, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoGeometry->countElements(dim)).c_str());
     GeometricElementList::iterator it = xaoGeometry->begin(dim);
     xmlNodePtr vertices = xmlNewChild(topology, 0, colTag, 0);
     xmlNewProp(vertices, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoGeometry->countElements(dim)).c_str());
     GeometricElementList::iterator it = xaoGeometry->begin(dim);
@@ -190,10 +197,10 @@ void XaoExporter::exportGeometricElements(Geometry* xaoGeometry,
         xmlNewProp(vertex, C_ATTR_ELT_NAME, BAD_CAST elt.getName().c_str());
         xmlNewProp(vertex, C_ATTR_ELT_REFERENCE, BAD_CAST elt.getReference().c_str());
     }
         xmlNewProp(vertex, C_ATTR_ELT_NAME, BAD_CAST elt.getName().c_str());
         xmlNewProp(vertex, C_ATTR_ELT_REFERENCE, BAD_CAST elt.getReference().c_str());
     }
-}
+  }
 
 
-void XaoExporter::exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePtr xao)
-{
+  void exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePtr xao)
+  {
     // Geometric part
     xmlNodePtr geometry = xmlNewChild(xao, 0, C_TAG_GEOMETRY, 0);
     xmlNewProp(geometry, C_ATTR_GEOMETRY_NAME, BAD_CAST xaoGeometry->getName().c_str());
     // Geometric part
     xmlNodePtr geometry = xmlNewChild(xao, 0, C_TAG_GEOMETRY, 0);
     xmlNewProp(geometry, C_ATTR_GEOMETRY_NAME, BAD_CAST xaoGeometry->getName().c_str());
@@ -210,10 +217,10 @@ void XaoExporter::exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePt
     exportGeometricElements(xaoGeometry, topology, XAO::EDGE, C_TAG_EDGES, C_TAG_EDGE);
     exportGeometricElements(xaoGeometry, topology, XAO::FACE, C_TAG_FACES, C_TAG_FACE);
     exportGeometricElements(xaoGeometry, topology, XAO::SOLID, C_TAG_SOLIDS, C_TAG_SOLID);
     exportGeometricElements(xaoGeometry, topology, XAO::EDGE, C_TAG_EDGES, C_TAG_EDGE);
     exportGeometricElements(xaoGeometry, topology, XAO::FACE, C_TAG_FACES, C_TAG_FACE);
     exportGeometricElements(xaoGeometry, topology, XAO::SOLID, C_TAG_SOLIDS, C_TAG_SOLID);
-}
+  }
 
 
-void XaoExporter::exportGroups(Xao* xaoObject, xmlNodePtr xao)
-{
+  void exportGroups(Xao* xaoObject, xmlNodePtr xao)
+  {
     xmlNodePtr groups = xmlNewChild(xao, 0, C_TAG_GROUPS, 0);
     xmlNewProp(groups, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoObject->countGroups()).c_str());
 
     xmlNodePtr groups = xmlNewChild(xao, 0, C_TAG_GROUPS, 0);
     xmlNewProp(groups, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoObject->countGroups()).c_str());
 
@@ -233,10 +240,10 @@ void XaoExporter::exportGroups(Xao* xaoObject, xmlNodePtr xao)
             xmlNewProp(elt, C_ATTR_ELEMENT_INDEX, BAD_CAST XaoUtils::intToString(grpElt).c_str());
         }
     }
             xmlNewProp(elt, C_ATTR_ELEMENT_INDEX, BAD_CAST XaoUtils::intToString(grpElt).c_str());
         }
     }
-}
+  }
 
 
-void XaoExporter::exportFields(Xao* xaoObject, xmlNodePtr xao)
-{
+  void exportFields(Xao* xaoObject, xmlNodePtr xao)
+  {
     xmlNodePtr fields = xmlNewChild(xao, 0, C_TAG_FIELDS, 0);
     xmlNewProp(fields, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoObject->countFields()).c_str());
 
     xmlNodePtr fields = xmlNewChild(xao, 0, C_TAG_FIELDS, 0);
     xmlNewProp(fields, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoObject->countFields()).c_str());
 
@@ -268,10 +275,10 @@ void XaoExporter::exportFields(Xao* xaoObject, xmlNodePtr xao)
             exportStep(step, field, nodeSteps);
         }
     }
             exportStep(step, field, nodeSteps);
         }
     }
-}
+  }
 
 
-void XaoExporter::exportStep(Step* step, Field* field, xmlNodePtr nodeSteps)
-{
+  void exportStep(Step* step, Field* field, xmlNodePtr nodeSteps)
+  {
     xmlNodePtr nodeStep = xmlNewChild(nodeSteps, 0, C_TAG_STEP, 0);
     xmlNewProp(nodeStep, C_ATTR_STEP_NUMBER, BAD_CAST XaoUtils::intToString(step->getStep()).c_str());
     if (step->getStamp() >= 0)
     xmlNodePtr nodeStep = xmlNewChild(nodeSteps, 0, C_TAG_STEP, 0);
     xmlNewProp(nodeStep, C_ATTR_STEP_NUMBER, BAD_CAST XaoUtils::intToString(step->getStep()).c_str());
     if (step->getStamp() >= 0)
@@ -291,39 +298,10 @@ void XaoExporter::exportStep(Step* step, Field* field, xmlNodePtr nodeSteps)
             xmlNewProp(nodeValue, C_ATTR_VALUE_COMPONENT, BAD_CAST XaoUtils::intToString(j).c_str());
         }
     }
             xmlNewProp(nodeValue, C_ATTR_VALUE_COMPONENT, BAD_CAST XaoUtils::intToString(j).c_str());
         }
     }
-}
-
-const bool XaoExporter::readFromFile(const std::string& fileName, Xao* xaoObject)
-throw (XAO_Exception)
-{
-    // parse the file and get the DOM
-    int options = XML_PARSE_HUGE || XML_PARSE_NOCDATA;
-    xmlDocPtr doc = xmlReadFile(fileName.c_str(), NULL, options);
-    if (doc == NULL)
-    {
-        throw XAO_Exception("Cannot read XAO file");
-    }
-
-    parseXMLDoc(doc, xaoObject);
-    return true;
-}
-
-const bool XaoExporter::setXML(const std::string& xml, Xao* xaoObject)
-throw (XAO_Exception)
-{
-    int options = XML_PARSE_HUGE || XML_PARSE_NOCDATA;
-    xmlDocPtr doc = xmlReadDoc(BAD_CAST xml.c_str(), "", NULL, options);
-    if (doc == NULL)
-    {
-        throw XAO_Exception("Cannot read XAO stream");
-    }
+  }
 
 
-    parseXMLDoc(doc, xaoObject);
-    return true;
-}
-
-void XaoExporter::parseXMLDoc(xmlDocPtr doc, Xao* xaoObject)
-{
+  void parseXMLDoc(xmlDocPtr doc, Xao* xaoObject)
+  {
     // Get the root element node
     xmlNodePtr root = xmlDocGetRootElement(doc);
     if (xmlStrcmp(root->name , C_TAG_XAO) != 0)
     // Get the root element node
     xmlNodePtr root = xmlDocGetRootElement(doc);
     if (xmlStrcmp(root->name , C_TAG_XAO) != 0)
@@ -333,10 +311,10 @@ void XaoExporter::parseXMLDoc(xmlDocPtr doc, Xao* xaoObject)
 
     xmlFreeDoc(doc);       // free document
     xmlCleanupParser();    // free globals
 
     xmlFreeDoc(doc);       // free document
     xmlCleanupParser();    // free globals
-}
+  }
 
 
-void XaoExporter::parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode, Xao* xaoObject)
-{
+  void parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode, Xao* xaoObject)
+  {
     std::string version = readStringProp(xaoNode, C_ATTR_XAO_VERSION, false, "");
     if (version != "")
         xaoObject->setAuthor(version);
     std::string version = readStringProp(xaoNode, C_ATTR_XAO_VERSION, false, "");
     if (version != "")
         xaoObject->setAuthor(version);
@@ -353,10 +331,10 @@ void XaoExporter::parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode, Xao* xaoObject
         else if (xmlStrcmp(node->name, C_TAG_FIELDS) == 0)
             parseFieldsNode(node, xaoObject);
     }
         else if (xmlStrcmp(node->name, C_TAG_FIELDS) == 0)
             parseFieldsNode(node, xaoObject);
     }
-}
+  }
 
 
-void XaoExporter::parseGeometryNode(xmlDocPtr doc, xmlNodePtr geometryNode, Xao* xaoObject)
-{
+  void parseGeometryNode(xmlDocPtr doc, xmlNodePtr geometryNode, Xao* xaoObject)
+  {
     // get the shape and topo nodes
     xmlNodePtr shapeNode = NULL;
     xmlNodePtr topoNode = NULL;
     // get the shape and topo nodes
     xmlNodePtr shapeNode = NULL;
     xmlNodePtr topoNode = NULL;
@@ -377,10 +355,10 @@ void XaoExporter::parseGeometryNode(xmlDocPtr doc, xmlNodePtr geometryNode, Xao*
     parseTopologyNode(topoNode, geometry);
 
     xaoObject->setGeometry(geometry);
     parseTopologyNode(topoNode, geometry);
 
     xaoObject->setGeometry(geometry);
-}
+  }
 
 
-void XaoExporter::parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode, Geometry* geometry)
-{
+  void parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode, Geometry* geometry)
+  {
     if (geometry->getFormat() == XAO::BREP)
     {
         xmlChar* data = xmlNodeGetContent(shapeNode->children);
     if (geometry->getFormat() == XAO::BREP)
     {
         xmlChar* data = xmlNodeGetContent(shapeNode->children);
@@ -394,10 +372,10 @@ void XaoExporter::parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode, Geometry*
         throw XAO_Exception(MsgBuilder() << "Shape format not supported: "
                                          << XaoUtils::shapeFormatToString(geometry->getFormat()));
     }
         throw XAO_Exception(MsgBuilder() << "Shape format not supported: "
                                          << XaoUtils::shapeFormatToString(geometry->getFormat()));
     }
-}
+  }
 
 
-void XaoExporter::parseTopologyNode(xmlNodePtr topologyNode, Geometry* geometry)
-{
+  void parseTopologyNode(xmlNodePtr topologyNode, Geometry* geometry)
+  {
     for (xmlNodePtr node = topologyNode->children; node; node = node->next)
     {
         if (xmlStrcmp(node->name, C_TAG_VERTICES) == 0)
     for (xmlNodePtr node = topologyNode->children; node; node = node->next)
     {
         if (xmlStrcmp(node->name, C_TAG_VERTICES) == 0)
@@ -409,10 +387,10 @@ void XaoExporter::parseTopologyNode(xmlNodePtr topologyNode, Geometry* geometry)
         else if (xmlStrcmp(node->name, C_TAG_SOLIDS) == 0)
             parseSolidsNode(node, geometry);
     }
         else if (xmlStrcmp(node->name, C_TAG_SOLIDS) == 0)
             parseSolidsNode(node, geometry);
     }
-}
+  }
 
 
-void XaoExporter::parseVerticesNode(xmlNodePtr verticesNode, Geometry* geometry)
-{
+  void parseVerticesNode(xmlNodePtr verticesNode, Geometry* geometry)
+  {
     int count = readIntegerProp(verticesNode, C_ATTR_COUNT, true, -1);
     geometry->setCountVertices(count);
 
     int count = readIntegerProp(verticesNode, C_ATTR_COUNT, true, -1);
     geometry->setCountVertices(count);
 
@@ -427,10 +405,10 @@ void XaoExporter::parseVerticesNode(xmlNodePtr verticesNode, Geometry* geometry)
             geometry->setVertex(index, name, reference);
         }
     }
             geometry->setVertex(index, name, reference);
         }
     }
-}
+  }
 
 
-void XaoExporter::parseEdgesNode(xmlNodePtr edgesNode, Geometry* geometry)
-{
+  void parseEdgesNode(xmlNodePtr edgesNode, Geometry* geometry)
+  {
     int count = readIntegerProp(edgesNode, C_ATTR_COUNT, true, -1);
     geometry->setCountEdges(count);
 
     int count = readIntegerProp(edgesNode, C_ATTR_COUNT, true, -1);
     geometry->setCountEdges(count);
 
@@ -445,10 +423,10 @@ void XaoExporter::parseEdgesNode(xmlNodePtr edgesNode, Geometry* geometry)
             geometry->setEdge(index, name, reference);
         }
     }
             geometry->setEdge(index, name, reference);
         }
     }
-}
+  }
 
 
-void XaoExporter::parseFacesNode(xmlNodePtr facesNode, Geometry* geometry)
-{
+  void parseFacesNode(xmlNodePtr facesNode, Geometry* geometry)
+  {
     int count = readIntegerProp(facesNode, C_ATTR_COUNT, true, -1);
     geometry->setCountFaces(count);
 
     int count = readIntegerProp(facesNode, C_ATTR_COUNT, true, -1);
     geometry->setCountFaces(count);
 
@@ -463,10 +441,10 @@ void XaoExporter::parseFacesNode(xmlNodePtr facesNode, Geometry* geometry)
             geometry->setFace(index, name, reference);
         }
     }
             geometry->setFace(index, name, reference);
         }
     }
-}
+  }
 
 
-void XaoExporter::parseSolidsNode(xmlNodePtr solidsNode, Geometry* geometry)
-{
+  void parseSolidsNode(xmlNodePtr solidsNode, Geometry* geometry)
+  {
     int count = readIntegerProp(solidsNode, C_ATTR_COUNT, true, -1);
     geometry->setCountSolids(count);
 
     int count = readIntegerProp(solidsNode, C_ATTR_COUNT, true, -1);
     geometry->setCountSolids(count);
 
@@ -481,10 +459,10 @@ void XaoExporter::parseSolidsNode(xmlNodePtr solidsNode, Geometry* geometry)
             geometry->setSolid(index, name, reference);
         }
     }
             geometry->setSolid(index, name, reference);
         }
     }
-}
+  }
 
 
-void XaoExporter::parseGroupsNode(xmlNodePtr groupsNode, Xao* xaoObject)
-{
+  void parseGroupsNode(xmlNodePtr groupsNode, Xao* xaoObject)
+  {
     for (xmlNodePtr node = groupsNode->children; node; node = node->next)
     {
         if (xmlStrcmp(node->name, C_TAG_GROUP) == 0)
     for (xmlNodePtr node = groupsNode->children; node; node = node->next)
     {
         if (xmlStrcmp(node->name, C_TAG_GROUP) == 0)
@@ -492,10 +470,10 @@ void XaoExporter::parseGroupsNode(xmlNodePtr groupsNode, Xao* xaoObject)
             parseGroupNode(node, xaoObject);
         }
     }
             parseGroupNode(node, xaoObject);
         }
     }
-}
+  }
 
 
-void XaoExporter::parseGroupNode(xmlNodePtr groupNode, Xao* xaoObject)
-{
+  void parseGroupNode(xmlNodePtr groupNode, Xao* xaoObject)
+  {
     std::string strDimension = readStringProp(groupNode, C_ATTR_GROUP_DIM, true, "");
     XAO::Dimension dim = XaoUtils::stringToDimension(strDimension);
     Group* group = xaoObject->addGroup(dim);
     std::string strDimension = readStringProp(groupNode, C_ATTR_GROUP_DIM, true, "");
     XAO::Dimension dim = XaoUtils::stringToDimension(strDimension);
     Group* group = xaoObject->addGroup(dim);
@@ -511,10 +489,10 @@ void XaoExporter::parseGroupNode(xmlNodePtr groupNode, Xao* xaoObject)
             group->add(index);
         }
     }
             group->add(index);
         }
     }
-}
+  }
 
 
-void XaoExporter::parseFieldsNode(xmlNodePtr fieldsNode, Xao* xaoObject)
-{
+  void parseFieldsNode(xmlNodePtr fieldsNode, Xao* xaoObject)
+  {
     for (xmlNodePtr node = fieldsNode->children; node; node = node->next)
     {
         if (xmlStrcmp(node->name, C_TAG_FIELD) == 0)
     for (xmlNodePtr node = fieldsNode->children; node; node = node->next)
     {
         if (xmlStrcmp(node->name, C_TAG_FIELD) == 0)
@@ -522,10 +500,10 @@ void XaoExporter::parseFieldsNode(xmlNodePtr fieldsNode, Xao* xaoObject)
             parseFieldNode(node, xaoObject);
         }
     }
             parseFieldNode(node, xaoObject);
         }
     }
-}
+  }
 
 
-void XaoExporter::parseFieldNode(xmlNodePtr fieldNode, Xao* xaoObject)
-{
+  void parseFieldNode(xmlNodePtr fieldNode, Xao* xaoObject)
+  {
     std::string strDimension = readStringProp(fieldNode, C_ATTR_FIELD_DIMENSION, true, "");
     XAO::Dimension dim = XaoUtils::stringToDimension(strDimension);
 
     std::string strDimension = readStringProp(fieldNode, C_ATTR_FIELD_DIMENSION, true, "");
     XAO::Dimension dim = XaoUtils::stringToDimension(strDimension);
 
@@ -581,10 +559,10 @@ void XaoExporter::parseFieldNode(xmlNodePtr fieldNode, Xao* xaoObject)
             }
         }
     }
             }
         }
     }
-}
+  }
 
 
-void XaoExporter::parseStepNode(xmlNodePtr stepNode, Field* field)
-{
+  void parseStepNode(xmlNodePtr stepNode, Field* field)
+  {
     int stepNumber = readIntegerProp(stepNode, C_ATTR_STEP_NUMBER, true, -1);
     Step* step = field->addNewStep(stepNumber);
 
     int stepNumber = readIntegerProp(stepNode, C_ATTR_STEP_NUMBER, true, -1);
     Step* step = field->addNewStep(stepNumber);
 
@@ -601,10 +579,10 @@ void XaoExporter::parseStepNode(xmlNodePtr stepNode, Field* field)
             parseStepElementNode(eltNode, step);
         }
     }
             parseStepElementNode(eltNode, step);
         }
     }
-}
+  }
 
 
-void XaoExporter::parseStepElementNode(xmlNodePtr eltNode, Step* step)
-{
+  void parseStepElementNode(xmlNodePtr eltNode, Step* step)
+  {
     int index = readIntegerProp(eltNode, C_ATTR_ELT_INDEX, true, -1);
 
     for (xmlNodePtr valNode = eltNode->children; valNode; valNode = valNode->next)
     int index = readIntegerProp(eltNode, C_ATTR_ELT_INDEX, true, -1);
 
     for (xmlNodePtr valNode = eltNode->children; valNode; valNode = valNode->next)
@@ -623,4 +601,58 @@ void XaoExporter::parseStepElementNode(xmlNodePtr eltNode, Step* step)
             step->setStringValue(index, component, value);
         }
     }
             step->setStringValue(index, component, value);
         }
     }
+  }
+}
+
+const bool XaoExporter::saveToFile(Xao* xaoObject, const std::string& fileName)
+throw (XAO_Exception)
+{
+    xmlDocPtr doc = exportXMLDoc(xaoObject);
+    xmlSaveFormatFileEnc(fileName.c_str(), doc, "UTF-8", 1); // format = 1 for node indentation
+    xmlFreeDoc(doc);
+
+    return true;
+}
+
+const std::string XaoExporter::saveToXml(Xao* xaoObject)
+throw (XAO_Exception)
+{
+    xmlDocPtr doc = exportXMLDoc(xaoObject);
+
+    xmlChar *xmlbuff;
+    int buffersize;
+    xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1); // format = 1 for node indentation
+    xmlFreeDoc(doc);
+    xmlCleanupGlobals();
+
+    return (char*)xmlbuff;
+}
+
+const bool XaoExporter::readFromFile(const std::string& fileName, Xao* xaoObject)
+throw (XAO_Exception)
+{
+    // parse the file and get the DOM
+    int options = XML_PARSE_HUGE || XML_PARSE_NOCDATA;
+    xmlDocPtr doc = xmlReadFile(fileName.c_str(), NULL, options);
+    if (doc == NULL)
+    {
+        throw XAO_Exception("Cannot read XAO file");
+    }
+
+    parseXMLDoc(doc, xaoObject);
+    return true;
+}
+
+const bool XaoExporter::setXML(const std::string& xml, Xao* xaoObject)
+throw (XAO_Exception)
+{
+    int options = XML_PARSE_HUGE || XML_PARSE_NOCDATA;
+    xmlDocPtr doc = xmlReadDoc(BAD_CAST xml.c_str(), "", NULL, options);
+    if (doc == NULL)
+    {
+        throw XAO_Exception("Cannot read XAO stream");
+    }
+
+    parseXMLDoc(doc, xaoObject);
+    return true;
 }
 }
index 6929b22b88c1aba4e07c782a8297cbf3c6f87f79..a63e921ca1ec6a2dca7c8d4ec3aa12b27b81ee8d 100644 (file)
@@ -21,8 +21,6 @@
 #ifndef __XAO_XAOEXPORTER_HXX__
 #define __XAO_XAOEXPORTER_HXX__
 
 #ifndef __XAO_XAOEXPORTER_HXX__
 #define __XAO_XAOEXPORTER_HXX__
 
-#include <libxml/parser.h>
-
 #include "XAO_Xao.hxx"
 #include "XAO_Geometry.hxx"
 #include "XAO_Group.hxx"
 #include "XAO_Xao.hxx"
 #include "XAO_Geometry.hxx"
 #include "XAO_Group.hxx"
@@ -71,37 +69,6 @@ namespace XAO
          */
         static const bool setXML(const std::string& xml, Xao* xaoObject)
         throw (XAO_Exception);
          */
         static const bool setXML(const std::string& xml, Xao* xaoObject)
         throw (XAO_Exception);
-
-    private:
-        static xmlDocPtr exportXMLDoc(Xao* xaoObject);
-        static void exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePtr xao);
-        static void exportGeometricElements(Geometry* xaoGeometry, xmlNodePtr topology,
-                XAO::Dimension dim, const xmlChar* colTag, const xmlChar* eltTag);
-        static void exportGroups(Xao* xaoObject, xmlNodePtr xao);
-        static void exportFields(Xao* xaoObject, xmlNodePtr xao);
-        static void exportStep(Step* step, Field* field, xmlNodePtr nodeSteps);
-
-        static void parseXMLDoc(xmlDocPtr doc, Xao* xaoObject);
-        static void parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode, Xao* xaoObject);
-        static void parseGeometryNode(xmlDocPtr doc, xmlNodePtr geometryNode, Xao* xaoObject);
-        static void parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode, Geometry* geometry);
-        static void parseTopologyNode(xmlNodePtr topologyNode, Geometry* geometry);
-        static void parseVerticesNode(xmlNodePtr verticesNode, Geometry* geometry);
-        static void parseEdgesNode(xmlNodePtr edgesNode, Geometry* geometry);
-        static void parseFacesNode(xmlNodePtr facesNode, Geometry* geometry);
-        static void parseSolidsNode(xmlNodePtr solidsNode, Geometry* geometry);
-        static void parseGroupsNode(xmlNodePtr groupsNode, Xao* xaoObject);
-        static void parseGroupNode(xmlNodePtr groupNode, Xao* xaoObject);
-
-        static void parseFieldsNode(xmlNodePtr fieldsNode, Xao* xaoObject);
-        static void parseFieldNode(xmlNodePtr fieldNode, Xao* xaoObject);
-        static void parseStepNode(xmlNodePtr stepNode, Field* field);
-        static void parseStepElementNode(xmlNodePtr eltNode, Step* step);
-
-        static std::string readStringProp(xmlNodePtr node, const xmlChar* attribute,
-                const bool& required, const std::string& defaultValue, const std::string& exception = std::string(""));
-        static int readIntegerProp(xmlNodePtr node, const xmlChar* attribute,
-                const bool& required, const int& defaultValue, const std::string& exception = std::string(""));
     };
 }
 
     };
 }