Ejemplo n.º 1
0
        /// <summary>
        /// Writes the data for XML serialization.
        /// </summary>
        /// <param name="writer">XML Writer.</param>
        public void WriteXml(XmlWriter writer)
        {
            XmlSerializer tripleSerializer = new XmlSerializer(typeof(Triple));

            // Serialize Base Uri
            if (BaseUri != null)
            {
                writer.WriteAttributeString("base", BaseUri.AbsoluteUri);
            }

            // Serialize Namespace Map
            writer.WriteStartElement("namespaces");
            foreach (String prefix in NamespaceMap.Prefixes)
            {
                writer.WriteStartElement("namespace");
                writer.WriteAttributeString("prefix", prefix);
                writer.WriteAttributeString("uri", NamespaceMap.GetNamespaceUri(prefix).AbsoluteUri);
                writer.WriteEndElement();
            }
            writer.WriteEndElement();

            // Serialize Triples
            writer.WriteStartElement("triples");
            foreach (Triple t in Triples)
            {
                tripleSerializer.Serialize(writer, t);
            }
            writer.WriteEndElement();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the Serialization Information for serializing a Graph.
        /// </summary>
        /// <param name="info">Serialization Information.</param>
        /// <param name="context">Streaming Context.</param>
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("base", BaseUri.ToSafeString());
            info.AddValue("triples", Triples.ToList(), typeof(List <Triple>));
            IEnumerable <KeyValuePair <String, String> > ns = from p in NamespaceMap.Prefixes
                                                              select new KeyValuePair <String, String>(p, NamespaceMap.GetNamespaceUri(p).AbsoluteUri);

            info.AddValue("namespaces", ns.ToList(), typeof(List <KeyValuePair <String, String> >));
        }