public System.Object DeserializeAnXMLFile(System.String xmlPathFile)
        {
            // Create xmlStream and load in the .XML file
            ESRI.ArcGIS.esriSystem.IXMLStream xmlStream = new ESRI.ArcGIS.esriSystem.XMLStreamClass();
            xmlStream.LoadFromFile(xmlPathFile);

            // Create xmlReader and read the XML stream
            ESRI.ArcGIS.esriSystem.IXMLReader xmlReader = new ESRI.ArcGIS.esriSystem.XMLReaderClass();
            xmlReader.ReadFrom((ESRI.ArcGIS.esriSystem.IStream)xmlStream); // Explicit Cast

            // Create a serializer
            ESRI.ArcGIS.esriSystem.IXMLSerializer xmlSerializer = new ESRI.ArcGIS.esriSystem.XMLSerializerClass();

            // Return the XML contents
            return(xmlSerializer.ReadObject(xmlReader, null, null));
        }
Beispiel #2
0
 public static string  XmlSerializer(System.Object xmlObject, System.String xmlNodeName)
 {
     System.String elementURI = "http://www.esri.com/schemas/ArcGIS/9.2";
     // Create xml writer
     ESRI.ArcGIS.esriSystem.IXMLWriter xmlWriterCls = new ESRI.ArcGIS.esriSystem.XMLWriterClass();
     // Create xml stream
     ESRI.ArcGIS.esriSystem.IXMLStream xmlStreamCls = new ESRI.ArcGIS.esriSystem.XMLStreamClass();
     // Explicit Cast for IStream and then write to stream
     xmlWriterCls.WriteTo((ESRI.ArcGIS.esriSystem.IStream)xmlStreamCls);
     // Serialize
     ESRI.ArcGIS.esriSystem.IXMLSerializer xmlSerializerCls = new ESRI.ArcGIS.esriSystem.XMLSerializerClass();
     xmlSerializerCls.WriteObject(xmlWriterCls, null, null, xmlNodeName, elementURI, xmlObject);
     // Save the xmlObject to an xml file. When using xmlstream the cpu keeps data in memory until it is written to file.
     //xmlStreamCls.SaveToFile(@xmlPathFile);
     return(xmlStreamCls.SaveToString());
 }
Beispiel #3
0
        private string SpatialReferenceToXml(ISpatialReference sr)
        {
            System.String elementURI = "http://www.esri.com/schemas/ArcGIS/9.2";

            // Create xml writer
            ESRI.ArcGIS.esriSystem.IXMLWriter xmlWriter = new ESRI.ArcGIS.esriSystem.XMLWriterClass();

            // Create xml stream
            ESRI.ArcGIS.esriSystem.IXMLStream xmlStream = new ESRI.ArcGIS.esriSystem.XMLStreamClass();

            // Explicit Cast for IStream and then write to stream
            xmlWriter.WriteTo((ESRI.ArcGIS.esriSystem.IStream)xmlStream);

            // Serialize
            ESRI.ArcGIS.esriSystem.IXMLSerializer xmlSerializer = new ESRI.ArcGIS.esriSystem.XMLSerializerClass();
            xmlSerializer.WriteObject(xmlWriter, null, null, "spatialreference", elementURI, sr);

            return(xmlStream.SaveToString());
        }
Beispiel #4
0
        private string SpatialReferenceToXml(ISpatialReference sr)
        {
            System.String elementURI = "http://www.esri.com/schemas/ArcGIS/9.2";

            // Create xml writer
            ESRI.ArcGIS.esriSystem.IXMLWriter xmlWriter = new ESRI.ArcGIS.esriSystem.XMLWriterClass();

            // Create xml stream
            ESRI.ArcGIS.esriSystem.IXMLStream xmlStream = new ESRI.ArcGIS.esriSystem.XMLStreamClass();

            // Explicit Cast for IStream and then write to stream
            xmlWriter.WriteTo((ESRI.ArcGIS.esriSystem.IStream)xmlStream);

            // Serialize
            ESRI.ArcGIS.esriSystem.IXMLSerializer xmlSerializer = new ESRI.ArcGIS.esriSystem.XMLSerializerClass();
            xmlSerializer.WriteObject(xmlWriter, null, null, "spatialreference", elementURI, sr);

            return xmlStream.SaveToString();
        }
Beispiel #5
0
        private string serializeGeo(ESRI.ArcGIS.Geometry.IGeometry geo, Boolean ESRISerialize)
        {
            if (ESRISerialize)
            {
                System.String xmlNodeName = "NodeName";
                System.String elementURI  = "http://www.esri.com/schemas/ArcGIS/10";

                // Create xml writer
                ESRI.ArcGIS.esriSystem.IXMLWriter xmlWriter = new ESRI.ArcGIS.esriSystem.XMLWriterClass();

                // Create xml stream
                ESRI.ArcGIS.esriSystem.IXMLStream xmlStream = new ESRI.ArcGIS.esriSystem.XMLStreamClass();

                // Explicit Cast for IStream and then write to stream
                xmlWriter.WriteTo((ESRI.ArcGIS.esriSystem.IStream)xmlStream);

                // Serialize
                ESRI.ArcGIS.esriSystem.IXMLSerializer xmlSerializer = new ESRI.ArcGIS.esriSystem.XMLSerializerClass();


                xmlSerializer.WriteObject(xmlWriter, null, null, xmlNodeName, elementURI, geo);

                return(xmlStream.SaveToString());
            }
            else
            {
                switch (geo.GeometryType)
                {
                case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
                {
                    ESRI.ArcGIS.Geometry.IPoint pPnt = (ESRI.ArcGIS.Geometry.IPoint)geo;

                    return("<Point><X>" + pPnt.X + "</X><Y>" + pPnt.Y + "</Y></Point>");

                    //break;
                }

                case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
                {
                    string lineString = "<PathArray>";
                    ESRI.ArcGIS.Geometry.IPolyline           pPly = (ESRI.ArcGIS.Geometry.IPolyline)geo;
                    ESRI.ArcGIS.Geometry.IGeometryCollection pGC  = (ESRI.ArcGIS.Geometry.IGeometryCollection)pPly;
                    for (int i = 0; i < pGC.GeometryCount; i++)
                    {
                        lineString = lineString + "<Path><PointArray>";
                        //ESRI.ArcGIS.Geometry.IGeometry pGeo2 = pGC.get_Geometry(i);
                        // ESRI.ArcGIS.Geometry.IPath pPath = (ESRI.ArcGIS.Geometry.IPath)pGC.get_Geometry(i);
                        ESRI.ArcGIS.Geometry.IPointCollection pPointCol = (ESRI.ArcGIS.Geometry.IPointCollection)pGC.get_Geometry(i);
                        for (int j = 0; j < pPointCol.PointCount; j++)
                        {
                            ESRI.ArcGIS.Geometry.IPoint pPathPoint = pPointCol.get_Point(j);

                            lineString = lineString + "<Point><X>" + pPathPoint.X + "</X><Y>" + pPathPoint.Y + "</Y></Point>";
                        }
                        // string tr = pGeo2.GeometryType.ToString();
                        lineString = lineString + "</PointArray></Path>";
                    }
                    lineString = lineString + "</PathArray>";
                    return(lineString);

                    // return "<Point><X>" + pPnt.X + "</X><Y>" + pPnt.Y + "</Y></Point>";
                    //     break;
                }

                default:
                {
                    return("");
                    //   break;
                }
                }
            }
        }