示例#1
0
        /// <summary>
        /// Reads the data for XML deserialization.
        /// </summary>
        /// <param name="reader">XML Reader.</param>
        public void ReadXml(XmlReader reader)
        {
            XmlSerializer tripleDeserializer = new XmlSerializer(typeof(Triple));

            reader.Read();
            if (reader.Name.Equals("namespaces"))
            {
                if (!reader.IsEmptyElement)
                {
                    reader.Read();
                    while (reader.Name.Equals("namespace"))
                    {
                        if (reader.MoveToAttribute("prefix"))
                        {
                            String prefix = reader.Value;
                            if (reader.MoveToAttribute("uri"))
                            {
                                Uri u = UriFactory.Create(reader.Value);
                                NamespaceMap.AddNamespace(prefix, u);
                                reader.Read();
                            }
                            else
                            {
                                throw new RdfParseException("Expected a uri attribute on a <namespace> element");
                            }
                        }
                        else
                        {
                            throw new RdfParseException("Expected a prefix attribute on a <namespace> element");
                        }
                    }
                }
            }
            reader.Read();
            if (reader.Name.Equals("triples"))
            {
                if (!reader.IsEmptyElement)
                {
                    reader.Read();
                    while (reader.Name.Equals("triple"))
                    {
                        try
                        {
                            Object temp = tripleDeserializer.Deserialize(reader);
                            Assert((Triple)temp);
                            reader.Read();
                        }
                        catch
                        {
                            throw;
                        }
                    }
                }
            }
            else
            {
                throw new RdfParseException("Expected a <triples> element inside a <graph> element but got a <" + reader.Name + "> element instead");
            }
        }
示例#2
0
 /// <summary>
 /// Creates a new Ontology Graph.
 /// </summary>
 public OntologyGraph()
 {
     NamespaceMap.AddNamespace("owl", UriFactory.Create(NamespaceMapper.OWL));
 }