Esempio n. 1
0
        /// <summary>
        /// Gives the collection of "xmlns" attributes of the "rdf:RDF" root node
        /// </summary>
        internal static XmlAttributeCollection GetXmlnsNamespaces(XmlNode rdfRDF, XmlNamespaceManager nsMgr)
        {
            XmlAttributeCollection xmlns = rdfRDF.Attributes;

            if (xmlns != null && xmlns.Count > 0)
            {
                IEnumerator iEnum = xmlns.GetEnumerator();
                while (iEnum != null && iEnum.MoveNext())
                {
                    XmlAttribute attr = (XmlAttribute)iEnum.Current;
                    if (attr.LocalName.ToUpperInvariant() != "XMLNS")
                    {
                        //Try to resolve the current namespace against the namespace register;
                        //if not resolved, create new namespace with scope limited to actual node
                        RDFNamespace ns =
                            (RDFNamespaceRegister.GetByPrefix(attr.LocalName) ??
                             RDFNamespaceRegister.GetByNamespace(attr.Value) ??
                             new RDFNamespace(attr.LocalName, attr.Value));

                        nsMgr.AddNamespace(ns.Prefix, ns.Namespace.ToString());
                    }
                }
            }
            return(xmlns);
        }
Esempio n. 2
0
        /// <summary>
        /// Default-ctor to initialize the singleton instance of the register
        /// </summary>
        static RDFNamespaceRegister()
        {
            RDFNamespace rdfsharp = new RDFNamespace(RDFVocabulary.RDFSHARP.PREFIX, RDFVocabulary.RDFSHARP.BASE_URI).SetDereferenceUri(new Uri(RDFVocabulary.RDFSHARP.DEREFERENCE_URI));

            Instance = new RDFNamespaceRegister()
            {
                Register = new List <RDFNamespace>()
                {
                    rdfsharp,
                    //Basic
                    new RDFNamespace(RDFVocabulary.RDF.PREFIX, RDFVocabulary.RDF.BASE_URI).SetDereferenceUri(new Uri(RDFVocabulary.RDF.DEREFERENCE_URI)),
                    new RDFNamespace(RDFVocabulary.RDFS.PREFIX, RDFVocabulary.RDFS.BASE_URI).SetDereferenceUri(new Uri(RDFVocabulary.RDFS.DEREFERENCE_URI)),
                    new RDFNamespace(RDFVocabulary.OWL.PREFIX, RDFVocabulary.OWL.BASE_URI).SetDereferenceUri(new Uri(RDFVocabulary.OWL.DEREFERENCE_URI)),
                    new RDFNamespace(RDFVocabulary.SHACL.PREFIX, RDFVocabulary.SHACL.BASE_URI).SetDereferenceUri(new Uri(RDFVocabulary.SHACL.DEREFERENCE_URI)),
                    new RDFNamespace(RDFVocabulary.XSD.PREFIX, RDFVocabulary.XSD.BASE_URI).SetDereferenceUri(new Uri(RDFVocabulary.XSD.DEREFERENCE_URI)),
                    new RDFNamespace(RDFVocabulary.XML.PREFIX, RDFVocabulary.XML.BASE_URI).SetDereferenceUri(new Uri(RDFVocabulary.XML.DEREFERENCE_URI)),
                    //Extended
                    new RDFNamespace(RDFVocabulary.DC.PREFIX, RDFVocabulary.DC.BASE_URI).SetDereferenceUri(new Uri(RDFVocabulary.DC.DEREFERENCE_URI)),
                    new RDFNamespace(RDFVocabulary.DC.DCAM.PREFIX, RDFVocabulary.DC.DCAM.BASE_URI).SetDereferenceUri(new Uri(RDFVocabulary.DC.DCAM.DEREFERENCE_URI)),
                    new RDFNamespace(RDFVocabulary.DC.DCTERMS.PREFIX, RDFVocabulary.DC.DCTERMS.BASE_URI).SetDereferenceUri(new Uri(RDFVocabulary.DC.DCTERMS.DEREFERENCE_URI)),
                    new RDFNamespace(RDFVocabulary.DC.DCTYPE.PREFIX, RDFVocabulary.DC.DCTYPE.BASE_URI).SetDereferenceUri(new Uri(RDFVocabulary.DC.DCTYPE.DEREFERENCE_URI)),
                    new RDFNamespace(RDFVocabulary.FOAF.PREFIX, RDFVocabulary.FOAF.BASE_URI).SetDereferenceUri(new Uri(RDFVocabulary.FOAF.DEREFERENCE_URI)),
                    new RDFNamespace(RDFVocabulary.GEO.PREFIX, RDFVocabulary.GEO.BASE_URI).SetDereferenceUri(new Uri(RDFVocabulary.GEO.DEREFERENCE_URI)),
                    new RDFNamespace(RDFVocabulary.SIOC.PREFIX, RDFVocabulary.SIOC.BASE_URI).SetDereferenceUri(new Uri(RDFVocabulary.SIOC.DEREFERENCE_URI)),
                    new RDFNamespace(RDFVocabulary.SKOS.PREFIX, RDFVocabulary.SKOS.BASE_URI).SetDereferenceUri(new Uri(RDFVocabulary.SKOS.DEREFERENCE_URI)),
                    new RDFNamespace(RDFVocabulary.SKOS.SKOSXL.PREFIX, RDFVocabulary.SKOS.SKOSXL.BASE_URI).SetDereferenceUri(new Uri(RDFVocabulary.SKOS.SKOSXL.DEREFERENCE_URI)),
                    new RDFNamespace(RDFVocabulary.EARL.PREFIX, RDFVocabulary.EARL.BASE_URI).SetDereferenceUri(new Uri(RDFVocabulary.EARL.DEREFERENCE_URI)),
                    new RDFNamespace(RDFVocabulary.CRM.PREFIX, RDFVocabulary.CRM.BASE_URI).SetDereferenceUri(new Uri(RDFVocabulary.CRM.DEREFERENCE_URI)),
                    new RDFNamespace(RDFVocabulary.DOAP.PREFIX, RDFVocabulary.DOAP.BASE_URI).SetDereferenceUri(new Uri(RDFVocabulary.DOAP.DEREFERENCE_URI)),
                    new RDFNamespace(RDFVocabulary.VS.PREFIX, RDFVocabulary.VS.BASE_URI).SetDereferenceUri(new Uri(RDFVocabulary.VS.DEREFERENCE_URI))
                }
            };

            DefaultNamespace = rdfsharp;
        }
Esempio n. 3
0
        /// <summary>
        /// Finds if the given token contains a recognizable namespace and, if so, abbreviates it with its prefix.
        /// It also prepares the result in a format useful for serialization.
        /// </summary>
        internal static String AbbreviateNamespace(String token)
        {
            //Null or Space token: it's a trick, give empty result
            if (token == null || token.Trim() == String.Empty)
            {
                return(String.Empty);
            }

            //Blank token: abbreviate it with "_"
            if (token.StartsWith("bnode:"))
            {
                return(token.Replace("bnode:", "_:"));
            }

            //Prefixed token: check if it starts with a known prefix, if so just return it
            if (RDFNamespaceRegister.GetByPrefix(token.Split(':')[0]) != null)
            {
                return(token);
            }

            //Uri token: search a known namespace, if found replace it with its prefix
            String  tokenBackup = token;
            Boolean abbrev      = false;

            RDFNamespaceRegister.Instance.Register.ForEach(ns => {
                if (!abbrev)
                {
                    String nS = ns.ToString();
                    if (!token.Equals(nS, StringComparison.OrdinalIgnoreCase))
                    {
                        if (token.StartsWith(nS))
                        {
                            token = token.Replace(nS, ns.NamespacePrefix + ":").TrimEnd(new Char[] { '/' });

                            //Accept the abbreviation only if it has generated a valid XSD QName
                            try {
                                var qn = new RDFTypedLiteral(token, RDFModelEnums.RDFDatatypes.XSD_QNAME);
                                abbrev = true;
                            }
                            catch {
                                token  = tokenBackup;
                                abbrev = false;
                            }
                        }
                    }
                }
            });

            //Search done, let's analyze results:
            if (abbrev)
            {
                return(token);        //token is a relative or a blank uri
            }
            if (token.Contains("^^")) //token is a typedLiteral absolute uri
            {
                return(token.Replace("^^", "^^<") + ">");
            }
            return("<" + token + ">"); //token is an absolute uri
        }
Esempio n. 4
0
        /// <summary>
        /// Default-ctor to initialize the singleton instance of the register
        /// </summary>
        static RDFNamespaceRegister()
        {
            Instance          = new RDFNamespaceRegister();
            Instance.Register = new List <RDFNamespace>();
            SetDefaultNamespace(new RDFNamespace("rdfsharp", "https://rdfsharp.codeplex.com/default_graph#"));

            #region Basic Namespaces
            //xsd
            AddNamespace(new RDFNamespace(RDFVocabulary.XSD.PREFIX, RDFVocabulary.XSD.BASE_URI));
            //xml
            AddNamespace(new RDFNamespace(RDFVocabulary.XML.PREFIX, RDFVocabulary.XML.BASE_URI));
            //rdf
            AddNamespace(new RDFNamespace(RDFVocabulary.RDF.PREFIX, RDFVocabulary.RDF.BASE_URI));
            //rdfs
            AddNamespace(new RDFNamespace(RDFVocabulary.RDFS.PREFIX, RDFVocabulary.RDFS.BASE_URI));
            //owl
            AddNamespace(new RDFNamespace(RDFVocabulary.OWL.PREFIX, RDFVocabulary.OWL.BASE_URI));
            #endregion

            #region Extended Namespaces
            //foaf
            AddNamespace(new RDFNamespace(RDFVocabulary.FOAF.PREFIX, RDFVocabulary.FOAF.BASE_URI));
            //skos (and extensions)
            AddNamespace(new RDFNamespace(RDFVocabulary.SKOS.PREFIX, RDFVocabulary.SKOS.BASE_URI));
            AddNamespace(new RDFNamespace(RDFVocabulary.SKOS.SKOSXL.PREFIX, RDFVocabulary.SKOS.SKOSXL.BASE_URI));
            //dc (and extensions)
            AddNamespace(new RDFNamespace(RDFVocabulary.DC.PREFIX, RDFVocabulary.DC.BASE_URI));
            AddNamespace(new RDFNamespace(RDFVocabulary.DC.DCAM.PREFIX, RDFVocabulary.DC.DCAM.BASE_URI));
            AddNamespace(new RDFNamespace(RDFVocabulary.DC.DCTERMS.PREFIX, RDFVocabulary.DC.DCTERMS.BASE_URI));
            AddNamespace(new RDFNamespace(RDFVocabulary.DC.DCTYPE.PREFIX, RDFVocabulary.DC.DCTYPE.BASE_URI));
            //geo
            AddNamespace(new RDFNamespace(RDFVocabulary.GEO.PREFIX, RDFVocabulary.GEO.BASE_URI));
            //sioc
            AddNamespace(new RDFNamespace(RDFVocabulary.SIOC.PREFIX, RDFVocabulary.SIOC.BASE_URI));
            //og (and extensions)
            AddNamespace(new RDFNamespace(RDFVocabulary.OG.PREFIX, RDFVocabulary.OG.BASE_URI));
            AddNamespace(new RDFNamespace(RDFVocabulary.OG.OG_MUSIC.PREFIX, RDFVocabulary.OG.OG_MUSIC.BASE_URI));
            AddNamespace(new RDFNamespace(RDFVocabulary.OG.OG_VIDEO.PREFIX, RDFVocabulary.OG.OG_VIDEO.BASE_URI));
            AddNamespace(new RDFNamespace(RDFVocabulary.OG.OG_ARTICLE.PREFIX, RDFVocabulary.OG.OG_ARTICLE.BASE_URI));
            AddNamespace(new RDFNamespace(RDFVocabulary.OG.OG_BOOK.PREFIX, RDFVocabulary.OG.OG_BOOK.BASE_URI));
            AddNamespace(new RDFNamespace(RDFVocabulary.OG.OG_PROFILE.PREFIX, RDFVocabulary.OG.OG_PROFILE.BASE_URI));
            AddNamespace(new RDFNamespace(RDFVocabulary.OG.OG_WEBSITE.PREFIX, RDFVocabulary.OG.OG_WEBSITE.BASE_URI));
            #endregion
        }
Esempio n. 5
0
        /// <summary>
        /// Default-ctor to initialize the singleton instance of the register
        /// </summary>
        static RDFNamespaceRegister()
        {
            Instance          = new RDFNamespaceRegister();
            Instance.Register = new List <RDFNamespace>();
            SetDefaultNamespace(new RDFNamespace("rdfsharp", "https://rdfsharp.codeplex.com/"));

            #region Basic Namespaces
            //xsd
            AddNamespace(new RDFNamespace(RDFVocabulary.XSD.PREFIX, RDFVocabulary.XSD.BASE_URI));
            //xml
            AddNamespace(new RDFNamespace(RDFVocabulary.XML.PREFIX, RDFVocabulary.XML.BASE_URI));
            //rdf
            AddNamespace(new RDFNamespace(RDFVocabulary.RDF.PREFIX, RDFVocabulary.RDF.BASE_URI));
            //rdfs
            AddNamespace(new RDFNamespace(RDFVocabulary.RDFS.PREFIX, RDFVocabulary.RDFS.BASE_URI));
            //owl
            AddNamespace(new RDFNamespace(RDFVocabulary.OWL.PREFIX, RDFVocabulary.OWL.BASE_URI));
            //sh
            AddNamespace(new RDFNamespace(RDFVocabulary.SHACL.PREFIX, RDFVocabulary.SHACL.BASE_URI));
            #endregion

            #region Extended Namespaces
            //dc
            AddNamespace(new RDFNamespace(RDFVocabulary.DC.PREFIX, RDFVocabulary.DC.BASE_URI));
            AddNamespace(new RDFNamespace(RDFVocabulary.DC.DCAM.PREFIX, RDFVocabulary.DC.DCAM.BASE_URI));
            AddNamespace(new RDFNamespace(RDFVocabulary.DC.DCTERMS.PREFIX, RDFVocabulary.DC.DCTERMS.BASE_URI));
            AddNamespace(new RDFNamespace(RDFVocabulary.DC.DCTYPE.PREFIX, RDFVocabulary.DC.DCTYPE.BASE_URI));
            //foaf
            AddNamespace(new RDFNamespace(RDFVocabulary.FOAF.PREFIX, RDFVocabulary.FOAF.BASE_URI));
            //earl
            AddNamespace(new RDFNamespace(RDFVocabulary.EARL.PREFIX, RDFVocabulary.EARL.BASE_URI));
            //geo
            AddNamespace(new RDFNamespace(RDFVocabulary.GEO.PREFIX, RDFVocabulary.GEO.BASE_URI));
            //sioc
            AddNamespace(new RDFNamespace(RDFVocabulary.SIOC.PREFIX, RDFVocabulary.SIOC.BASE_URI));
            //skos
            AddNamespace(new RDFNamespace(RDFVocabulary.SKOS.PREFIX, RDFVocabulary.SKOS.BASE_URI));
            AddNamespace(new RDFNamespace(RDFVocabulary.SKOS.SKOSXL.PREFIX, RDFVocabulary.SKOS.SKOSXL.BASE_URI));
            #endregion
        }
Esempio n. 6
0
        /// <summary>
        /// Serializes the given graph to the given stream using XML data format.
        /// </summary>
        internal static void Serialize(RDFGraph graph, Stream outputStream)
        {
            try {
                #region serialize
                using (XmlTextWriter rdfxmlWriter = new XmlTextWriter(outputStream, Encoding.UTF8))  {
                    XmlDocument rdfDoc = new XmlDocument();
                    rdfxmlWriter.Formatting = Formatting.Indented;

                    #region xmlDecl
                    XmlDeclaration xmlDecl = rdfDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
                    rdfDoc.AppendChild(xmlDecl);
                    #endregion

                    #region rdfRoot
                    XmlNode      rdfRoot       = rdfDoc.CreateNode(XmlNodeType.Element, RDFVocabulary.RDF.PREFIX + ":RDF", RDFVocabulary.RDF.BASE_URI);
                    XmlAttribute rdfRootNS     = rdfDoc.CreateAttribute("xmlns:" + RDFVocabulary.RDF.PREFIX);
                    XmlText      rdfRootNSText = rdfDoc.CreateTextNode(RDFVocabulary.RDF.BASE_URI);
                    rdfRootNS.AppendChild(rdfRootNSText);
                    rdfRoot.Attributes.Append(rdfRootNS);

                    #region prefixes
                    //Write the graph's prefixes (except for "rdf", which has already been written)
                    graph.GraphMetadata.Namespaces.ForEach(p => {
                        if (!p.Prefix.Equals(RDFVocabulary.RDF.PREFIX, StringComparison.Ordinal) && !p.Prefix.Equals("base", StringComparison.Ordinal))
                        {
                            XmlAttribute pfRootNS = rdfDoc.CreateAttribute("xmlns:" + p.Prefix);
                            XmlText pfRootNSText  = rdfDoc.CreateTextNode(p.ToString());
                            pfRootNS.AppendChild(pfRootNSText);
                            rdfRoot.Attributes.Append(pfRootNS);
                        }
                    });
                    //Write the graph's base uri to resolve eventual relative #IDs
                    XmlAttribute pfBaseNS     = rdfDoc.CreateAttribute(RDFVocabulary.XML.PREFIX + ":base");
                    XmlText      pfBaseNSText = rdfDoc.CreateTextNode(graph.Context.ToString());
                    pfBaseNS.AppendChild(pfBaseNSText);
                    rdfRoot.Attributes.Append(pfBaseNS);
                    #endregion

                    #region linq
                    //Group the graph's triples by subj
                    var groupedList = (from triple in graph
                                       orderby triple.Subject.ToString()
                                       group triple by new {
                        subj = triple.Subject.ToString()
                    });
                    #endregion

                    #region graph
                    //Iterate over the calculated groups
                    Dictionary <RDFResource, XmlNode> containers = new Dictionary <RDFResource, XmlNode>();

                    //Floating containers have reification subject which is never object of any graph's triple
                    Boolean floatingContainers = graph.GraphMetadata.Containers.Keys.Any(k =>
                                                                                         graph.Triples.Values.Count(v => v.Object.Equals(k)) == 0);
                    //Floating collections have reification subject which is never object of any graph's triple
                    Boolean floatingCollections = graph.GraphMetadata.Collections.Keys.Any(k =>
                                                                                           graph.Triples.Values.Count(v => v.Object.Equals(k)) == 0);

                    foreach (var group in groupedList)
                    {
                        #region subj
                        //Check if the current subj is a container or a collection subj: if so it must be
                        //serialized in the canonical RDF/XML way instead of the "rdf:Description" way
                        XmlNode subjNode = null;
                        String  subj     = group.Key.subj;

                        //It is a container subj, so add it to the containers pool
                        if (graph.GraphMetadata.Containers.Keys.Any(k => k.ToString().Equals(subj, StringComparison.Ordinal)) && !floatingContainers)
                        {
                            switch (graph.GraphMetadata.Containers.Single(c => c.Key.ToString().Equals(subj, StringComparison.Ordinal)).Value)
                            {
                            case RDFModelEnums.RDFContainerType.Bag:
                                subjNode = rdfDoc.CreateNode(XmlNodeType.Element, RDFVocabulary.RDF.PREFIX + ":Bag", RDFVocabulary.RDF.BASE_URI);
                                containers.Add(new RDFResource(subj), subjNode);
                                break;

                            case RDFModelEnums.RDFContainerType.Seq:
                                subjNode = rdfDoc.CreateNode(XmlNodeType.Element, RDFVocabulary.RDF.PREFIX + ":Seq", RDFVocabulary.RDF.BASE_URI);
                                containers.Add(new RDFResource(subj), subjNode);
                                break;

                            case RDFModelEnums.RDFContainerType.Alt:
                                subjNode = rdfDoc.CreateNode(XmlNodeType.Element, RDFVocabulary.RDF.PREFIX + ":Alt", RDFVocabulary.RDF.BASE_URI);
                                containers.Add(new RDFResource(subj), subjNode);
                                break;
                            }
                        }

                        //It is a subj of a collection of resources, so do not append triples having it as a subject
                        //because we will reconstruct the collection and append it as a whole
                        else if (graph.GraphMetadata.Collections.Keys.Any(k => k.ToString().Equals(subj, StringComparison.Ordinal)) &&
                                 graph.GraphMetadata.Collections.Single(c => c.Key.ToString().Equals(subj, StringComparison.Ordinal)).Value.ItemType == RDFModelEnums.RDFItemType.Resource &&
                                 !floatingCollections)
                        {
                            continue;
                        }

                        //It is neither a container or a collection subj
                        else
                        {
                            subjNode = rdfDoc.CreateNode(XmlNodeType.Element, RDFVocabulary.RDF.PREFIX + ":Description", RDFVocabulary.RDF.BASE_URI);
                            //<rdf:Description rdf:nodeID="blankID">
                            XmlAttribute subjNodeDesc     = null;
                            XmlText      subjNodeDescText = rdfDoc.CreateTextNode(group.Key.subj);
                            if (group.Key.subj.StartsWith("bnode:"))
                            {
                                subjNodeDescText.InnerText = subjNodeDescText.InnerText.Replace("bnode:", String.Empty);
                                subjNodeDesc = rdfDoc.CreateAttribute(RDFVocabulary.RDF.PREFIX + ":nodeID", RDFVocabulary.RDF.BASE_URI);
                            }
                            //<rdf:Description rdf:about="subjURI">
                            else
                            {
                                subjNodeDesc = rdfDoc.CreateAttribute(RDFVocabulary.RDF.PREFIX + ":about", RDFVocabulary.RDF.BASE_URI);
                            }
                            subjNodeDesc.AppendChild(subjNodeDescText);
                            subjNode.Attributes.Append(subjNodeDesc);
                        }
                        #endregion

                        #region predObjList
                        //Iterate over the triples of the current group
                        foreach (var triple in group)
                        {
                            //Do not append the triple if it is "SUBJECT rdf:type rdf:[Bag|Seq|Alt]"
                            if (!(triple.Predicate.Equals(RDFVocabulary.RDF.TYPE) &&
                                  (subjNode.Name.Equals(RDFVocabulary.RDF.PREFIX + ":Bag", StringComparison.Ordinal) ||
                                   subjNode.Name.Equals(RDFVocabulary.RDF.PREFIX + ":Seq", StringComparison.Ordinal) ||
                                   subjNode.Name.Equals(RDFVocabulary.RDF.PREFIX + ":Alt", StringComparison.Ordinal))))
                            {
                                #region pred
                                String predString = triple.Predicate.ToString();
                                //"<predPREF:predURI"
                                RDFNamespace predNS =
                                    (RDFNamespaceRegister.GetByNamespace(predString) ??
                                     RDFModelUtilities.GenerateNamespace(predString, false));
                                //Refine the pred with eventually necessary sanitizations
                                String predUri = predString.Replace(predNS.ToString(), predNS.Prefix + ":")
                                                 .Replace(":#", ":")
                                                 .TrimEnd(new Char[] { ':', '/' });
                                //Sanitize eventually detected automatic namespace
                                if (predUri.StartsWith("autoNS:"))
                                {
                                    predUri = predUri.Replace("autoNS:", string.Empty);
                                }
                                //Do not write "xmlns" attribute if the predUri is the context of the graph
                                XmlNode predNode = null;
                                if (predNS.ToString().Equals(graph.Context.ToString(), StringComparison.Ordinal))
                                {
                                    predNode = rdfDoc.CreateNode(XmlNodeType.Element, predUri, null);
                                }
                                else
                                {
                                    predNode = rdfDoc.CreateNode(XmlNodeType.Element, predUri, predNS.ToString());
                                }
                                #endregion

                                #region object
                                if (triple.TripleFlavor == RDFModelEnums.RDFTripleFlavor.SPO)
                                {
                                    //If the object is a container subj, we must append its entire node saved in the containers dictionary
                                    if (containers.Keys.Any(k => k.Equals(triple.Object)) && !floatingContainers)
                                    {
                                        predNode.AppendChild(containers.Single(c => c.Key.Equals(triple.Object)).Value);
                                    }

                                    //Else, if the object is a subject of a collection of resources, we must append the "rdf:parseType=Collection" attribute to the predicate node
                                    else if (graph.GraphMetadata.Collections.Keys.Any(k => k.Equals(triple.Object)) &&
                                             graph.GraphMetadata.Collections.Single(c => c.Key.Equals(triple.Object)).Value.ItemType == RDFModelEnums.RDFItemType.Resource &&
                                             !floatingCollections)
                                    {
                                        XmlAttribute rdfParseType     = rdfDoc.CreateAttribute(RDFVocabulary.RDF.PREFIX + ":parseType", RDFVocabulary.RDF.BASE_URI);
                                        XmlText      rdfParseTypeText = rdfDoc.CreateTextNode("Collection");
                                        rdfParseType.AppendChild(rdfParseTypeText);
                                        predNode.Attributes.Append(rdfParseType);
                                        //Then we append sequentially the collection elements
                                        List <XmlNode> collElements = ReconstructCollection(graph.GraphMetadata, (RDFResource)triple.Object, rdfDoc);
                                        collElements.ForEach(c => predNode.AppendChild(c));
                                    }

                                    //Else, threat it as a traditional object node
                                    else
                                    {
                                        String       objString        = triple.Object.ToString();
                                        XmlAttribute predNodeDesc     = null;
                                        XmlText      predNodeDescText = rdfDoc.CreateTextNode(objString);
                                        //  rdf:nodeID="blankID">
                                        if (objString.StartsWith("bnode:"))
                                        {
                                            predNodeDescText.InnerText = predNodeDescText.InnerText.Replace("bnode:", String.Empty);
                                            predNodeDesc = rdfDoc.CreateAttribute(RDFVocabulary.RDF.PREFIX + ":nodeID", RDFVocabulary.RDF.BASE_URI);
                                        }
                                        //  rdf:resource="objURI">
                                        else
                                        {
                                            predNodeDesc = rdfDoc.CreateAttribute(RDFVocabulary.RDF.PREFIX + ":resource", RDFVocabulary.RDF.BASE_URI);
                                        }
                                        predNodeDesc.AppendChild(predNodeDescText);
                                        predNode.Attributes.Append(predNodeDesc);
                                    }
                                }
                                #endregion

                                #region literal
                                else
                                {
                                    #region plain literal
                                    if (triple.Object is RDFPlainLiteral)
                                    {
                                        RDFPlainLiteral pLit = (RDFPlainLiteral)triple.Object;
                                        //  xml:lang="plitLANG">
                                        if (pLit.Language != String.Empty)
                                        {
                                            XmlAttribute plainLiteralLangNodeDesc     = rdfDoc.CreateAttribute(RDFVocabulary.XML.PREFIX + ":lang", RDFVocabulary.XML.BASE_URI);
                                            XmlText      plainLiteralLangNodeDescText = rdfDoc.CreateTextNode(pLit.Language);
                                            plainLiteralLangNodeDesc.AppendChild(plainLiteralLangNodeDescText);
                                            predNode.Attributes.Append(plainLiteralLangNodeDesc);
                                        }
                                    }
                                    #endregion

                                    #region typed literal
                                    //  rdf:datatype="tlitURI">
                                    else
                                    {
                                        RDFTypedLiteral tLit = (RDFTypedLiteral)triple.Object;
                                        XmlAttribute    typedLiteralNodeDesc     = rdfDoc.CreateAttribute(RDFVocabulary.RDF.PREFIX + ":datatype", RDFVocabulary.RDF.BASE_URI);
                                        XmlText         typedLiteralNodeDescText = rdfDoc.CreateTextNode(RDFModelUtilities.GetDatatypeFromEnum(tLit.Datatype));
                                        typedLiteralNodeDesc.AppendChild(typedLiteralNodeDescText);
                                        predNode.Attributes.Append(typedLiteralNodeDesc);
                                    }
                                    #endregion

                                    //litVALUE</predPREF:predURI>"
                                    XmlText litNodeDescText = rdfDoc.CreateTextNode(((RDFLiteral)triple.Object).Value);
                                    predNode.AppendChild(litNodeDescText);
                                }
                                #endregion

                                subjNode.AppendChild(predNode);
                            }
                        }

                        //Raw containers must not be written as-is, instead they have to be saved
                        //and attached when their subj is found later as object of a triple
                        if (!subjNode.Name.Equals(RDFVocabulary.RDF.PREFIX + ":Bag", StringComparison.Ordinal) &&
                            !subjNode.Name.Equals(RDFVocabulary.RDF.PREFIX + ":Seq", StringComparison.Ordinal) &&
                            !subjNode.Name.Equals(RDFVocabulary.RDF.PREFIX + ":Alt", StringComparison.Ordinal))
                        {
                            rdfRoot.AppendChild(subjNode);
                        }
                        #endregion
                    }
                    #endregion

                    rdfDoc.AppendChild(rdfRoot);
                    #endregion

                    rdfDoc.Save(rdfxmlWriter);
                }
                #endregion
            }
            catch (Exception ex) {
                throw new RDFModelException("Cannot serialize Xml because: " + ex.Message, ex);
            }
        }