#region Disclaimer / License // Copyright (C) 2010, Jackie Ng // http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie@gmail.com // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // #endregion using System; using System.Collections.Generic; using System.Text; using System.Xml; using System.IO; namespace OSGeo.MapGuide.MaestroAPI { public class XmlFeatureSetReader : FeatureSetReader { private XmlTextReader m_reader; //TODO: Make internal public XmlFeatureSetReader(Stream m_source) : base() { m_reader = new XmlTextReader(m_source); m_reader.WhitespaceHandling = WhitespaceHandling.Significant; //First we extract the response layout m_reader.Read(); if (m_reader.Name != "xml") throw new Exception("Bad document"); m_reader.Read(); if (m_reader.Name != "FeatureSet" && m_reader.Name != "PropertySet" && m_reader.Name != "RowSet") throw new Exception("Bad document"); m_reader.Read(); if (m_reader.Name != "xs:schema" && m_reader.Name != "PropertyDefinitions" && m_reader.Name != "ColumnDefinitions") throw new Exception("Bad document"); XmlDocument doc = new XmlDocument(); doc.LoadXml(m_reader.ReadOuterXml()); XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable); mgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema"); mgr.AddNamespace("gml", "http://www.opengis.net/gml"); mgr.AddNamespace("fdo", "http://fdo.osgeo.org/schemas"); //TODO: Assumes there is only one type returned... perhaps more can be returned.... XmlNodeList lst = doc.SelectNodes("xs:schema/xs:complexType/xs:complexContent/xs:extension/xs:sequence/xs:element", mgr); if (lst.Count == 0) lst = doc.SelectNodes("xs:schema/xs:complexType/xs:sequence/xs:element", mgr); if (lst.Count == 0) lst = doc.SelectNodes("PropertyDefinitions/PropertyDefinition"); if (lst.Count == 0) lst = doc.SelectNodes("ColumnDefinitions/Column"); FeatureSetColumn[] cols = new FeatureSetColumn[lst.Count]; for(int i = 0;i