RDFGraphMetadata represents a collector for metadata describing contents of a RDFGraph.
コード例 #1
0
        /// <summary>
        /// Given the metadata of a graph and a collection resource, it reconstructs the RDF collection and returns it as a list of nodes
        /// This is needed for building the " rdf:parseType=Collection>" RDF/XML abbreviation goody for collections of resources
        /// </summary>
        internal static List <XmlNode> ReconstructCollection(RDFGraphMetadata rdfGraphMetadata, RDFResource tripleObject, XmlDocument rdfDoc)
        {
            List <XmlNode> result              = new List <XmlNode>();
            Boolean        nilFound            = false;
            XmlNode        collElementToAppend = null;
            XmlAttribute   collElementAttr     = null;
            XmlText        collElementAttrText = null;

            //Iterate the elements of the collection until the last one (pointing to next="rdf:nil")
            while (!nilFound)
            {
                var collElement = rdfGraphMetadata.Collections[tripleObject];
                collElementToAppend = rdfDoc.CreateNode(XmlNodeType.Element, RDFVocabulary.RDF.PREFIX + ":Description", RDFVocabulary.RDF.BASE_URI);
                collElementAttr     = rdfDoc.CreateAttribute(RDFVocabulary.RDF.PREFIX + ":about", RDFVocabulary.RDF.BASE_URI);
                collElementAttrText = rdfDoc.CreateTextNode(collElement.ItemValue.ToString());
                if (collElementAttrText.InnerText.StartsWith("bnode:"))
                {
                    collElementAttrText.InnerText = collElementAttrText.InnerText.Replace("bnode:", String.Empty);
                }
                collElementAttr.AppendChild(collElementAttrText);
                collElementToAppend.Attributes.Append(collElementAttr);
                result.Add(collElementToAppend);

                //Verify if this is the last element of the collection (pointing to next="rdf:nil")
                if (collElement.ItemNext.ToString().Equals(RDFVocabulary.RDF.NIL.ToString(), StringComparison.Ordinal))
                {
                    nilFound = true;
                }
                else
                {
                    tripleObject = collElement.ItemNext as RDFResource;
                }
            }

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Given the metadata of a graph and a collection resource, it reconstructs the RDF collection and returns it as a list of nodes
        /// This is needed for building the " rdf:parseType=Collection>" RDF/XML abbreviation goody for collections of resources
        /// </summary>
        internal static List<XmlNode> ReconstructCollection(RDFGraphMetadata rdfGraphMetadata, RDFResource tripleObject, XmlDocument rdfDoc) {
            List<XmlNode> result          = new List<XmlNode>();
            Boolean nilFound              = false;
            XmlNode collElementToAppend   = null;
            XmlAttribute collElementAttr  = null;
            XmlText collElementAttrText   = null;

            //Iterate the elements of the collection until the last one (pointing to next="rdf:nil")
            while (!nilFound) {
                var collElement           = rdfGraphMetadata.Collections[tripleObject];
                collElementToAppend       = rdfDoc.CreateNode(XmlNodeType.Element, RDFVocabulary.RDF.PREFIX + ":Description", RDFVocabulary.RDF.BASE_URI);
                collElementAttr           = rdfDoc.CreateAttribute(RDFVocabulary.RDF.PREFIX + ":about", RDFVocabulary.RDF.BASE_URI);
                collElementAttrText       = rdfDoc.CreateTextNode(collElement.ItemValue.ToString());
                if (collElementAttrText.InnerText.StartsWith("bnode:")) {
                    collElementAttrText.InnerText = collElementAttrText.InnerText.Replace("bnode:", String.Empty);
                }
                collElementAttr.AppendChild(collElementAttrText);
                collElementToAppend.Attributes.Append(collElementAttr);
                result.Add(collElementToAppend);

                //Verify if this is the last element of the collection (pointing to next="rdf:nil")
                if (collElement.ItemNext.ToString().Equals(RDFVocabulary.RDF.NIL.ToString(), StringComparison.Ordinal)) {
                    nilFound              = true;
                }
                else {
                    tripleObject          = collElement.ItemNext as RDFResource;
                }

            }

            return result;
        }