Ejemplo n.º 1
0
        public void subjectUsedTypedNodeIfRdfTypeSpecified()
        {
            XmlWriterStore xmlWriter = new XmlWriterStore();
            RdfXmlWriter   rdfWriter = new RdfXmlWriter(xmlWriter);

            rdfWriter.RegisterNamespacePrefix("http://example.com/", "ex");

            rdfWriter.StartOutput();
            rdfWriter.StartSubject();
            rdfWriter.WriteUriRef("http://example.com/subj");
            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://foo.example.com/name");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();
            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/Thing");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();
            rdfWriter.EndSubject();
            rdfWriter.EndOutput();

            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("ex", "Thing", "http://example.com/"));
        }
Ejemplo n.º 2
0
        public void subjectUsesOnlyFirstRdfTypePropertyToDetermineTypedNode()
        {
            XmlWriterStore xmlWriter = new XmlWriterStore();
            RdfXmlWriter   rdfWriter = new RdfXmlWriter(xmlWriter);

            rdfWriter.RegisterNamespacePrefix("http://example.com/", "ex");

            rdfWriter.StartOutput();
            rdfWriter.StartSubject();
            rdfWriter.WriteUriRef("http://example.com/subj");
            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://foo.example.com/name");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();
            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/Thing");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();
            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/Other");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();
            rdfWriter.EndSubject();
            rdfWriter.EndOutput();

            Assert.IsFalse(xmlWriter.WasWriteStartElementCalledWith("ex", "Other", "http://example.com/"));
        }
Ejemplo n.º 3
0
        public void newNamespacePrefixesAreRememberedAndReused()
        {
            XmlWriterStore xmlWriter = new XmlWriterStore();
            RdfXmlWriter   rdfWriter = new RdfXmlWriter(xmlWriter);

            rdfWriter.StartOutput();
            rdfWriter.StartSubject();
            rdfWriter.WriteUriRef("http://example.com/subj");
            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://foo.example.com/name");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();
            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://bar.example.com/name");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();

            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://foo.example.com/place");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();

            rdfWriter.EndSubject();
            rdfWriter.EndOutput();

            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("ns1", "place", "http://foo.example.com/"), "first new namespace reused");
        }
Ejemplo n.º 4
0
        public void newNamespacesAreAssignedNewPrefixes()
        {
            XmlWriterStore xmlWriter = new XmlWriterStore();
            RdfXmlWriter   rdfWriter = new RdfXmlWriter(xmlWriter);

            rdfWriter.StartOutput();
            rdfWriter.StartSubject();
            rdfWriter.WriteUriRef("http://example.com/subj");
            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://foo.example.com/name");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();
            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://bar.example.com/name");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();

            rdfWriter.EndSubject();
            rdfWriter.EndOutput();

            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("ns1", "name", "http://foo.example.com/"), "first new namespace assigned");
            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("ns2", "name", "http://bar.example.com/"), "second new namespace assigned");
        }
Ejemplo n.º 5
0
        public void writerWritesPredicateElement()
        {
            XmlWriterStore xmlWriter = new XmlWriterStore();
            RdfXmlWriter   rdfWriter = new RdfXmlWriter(xmlWriter);

            writeSingleUUUTriple(rdfWriter);
            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("ns1", "pred", "http://example.com/"));
        }
Ejemplo n.º 6
0
        public void writerWritesRdfDescriptionForUntypedSubject()
        {
            XmlWriterStore xmlWriter = new XmlWriterStore();
            RdfXmlWriter   rdfWriter = new RdfXmlWriter(xmlWriter);

            writeSingleUUUTriple(rdfWriter);

            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("rdf", "Description", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"));
        }
Ejemplo n.º 7
0
        public void writerStartsRdfRootElement()
        {
            XmlWriterStore xmlWriter = new XmlWriterStore();
            RdfXmlWriter   rdfWriter = new RdfXmlWriter(xmlWriter);

            writeSingleUUUTriple(rdfWriter);

            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("rdf", "RDF", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"));
        }
Ejemplo n.º 8
0
        public void writerWritesXmlPrologAsStandalone()
        {
            XmlWriterStore xmlWriter = new XmlWriterStore();
            RdfXmlWriter   rdfWriter = new RdfXmlWriter(xmlWriter);

            writeSingleUUUTriple(rdfWriter);

            Assert.IsTrue(xmlWriter.WasWriteStartDocumentCalledWith(true));
        }
Ejemplo n.º 9
0
        public void writerWritesRdfNodeIdForBlankNodeObject()
        {
            XmlWriterStore xmlWriter = new XmlWriterStore();
            RdfXmlWriter   rdfWriter = new RdfXmlWriter(xmlWriter);

            writeSingleUUBTriple(rdfWriter);

            Assert.IsTrue(xmlWriter.WasWriteStartAttributeCalledWith("rdf", "nodeID", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"), "start attribute");
            Assert.IsTrue(xmlWriter.WasWriteStringCalledWith("genid1"), "attribute content");
        }
Ejemplo n.º 10
0
        public void writerWritesRdfResourceForUriRefObject()
        {
            XmlWriterStore xmlWriter = new XmlWriterStore();
            RdfXmlWriter   rdfWriter = new RdfXmlWriter(xmlWriter);

            writeSingleUUUTriple(rdfWriter);

            Assert.IsTrue(xmlWriter.WasWriteStartAttributeCalledWith("rdf", "resource", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"), "start attribute");
            Assert.IsTrue(xmlWriter.WasWriteStringCalledWith("http://example.com/obj"), "attribute content");
        }
Ejemplo n.º 11
0
        public void writerMapsNodeIdsToNewValues()
        {
            XmlWriterStore xmlWriter = new XmlWriterStore();
            RdfXmlWriter   rdfWriter = new RdfXmlWriter(xmlWriter);

            rdfWriter.RegisterNamespacePrefix("http://example.com/", "ex");

            rdfWriter.StartOutput();
            rdfWriter.StartSubject();
            rdfWriter.WriteBlankNode("foo");
            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://example.com/pred");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();
            rdfWriter.EndSubject();
            rdfWriter.EndOutput();

            Assert.IsFalse(xmlWriter.WasWriteStringCalledWith("foo"), "attribute content");
        }
Ejemplo n.º 12
0
        public void registerNamespacePrefix()
        {
            XmlWriterStore xmlWriter = new XmlWriterStore();
            RdfXmlWriter   rdfWriter = new RdfXmlWriter(xmlWriter);

            rdfWriter.RegisterNamespacePrefix("http://foo.example.com/", "foo");

            rdfWriter.StartOutput();
            rdfWriter.StartSubject();
            rdfWriter.WriteUriRef("http://example.com/subj");
            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://foo.example.com/name");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();
            rdfWriter.EndSubject();
            rdfWriter.EndOutput();

            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("foo", "name", "http://foo.example.com/"));
        }
Ejemplo n.º 13
0
        public void rdfNamespacePrefixCanBeChanged()
        {
            XmlWriterStore xmlWriter = new XmlWriterStore();
            RdfXmlWriter   rdfWriter = new RdfXmlWriter(xmlWriter);

            rdfWriter.RegisterNamespacePrefix("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "wtf");

            rdfWriter.StartOutput();
            rdfWriter.StartSubject();
            rdfWriter.WriteUriRef("http://example.com/subj");
            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://foo.example.com/name");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();
            rdfWriter.EndSubject();
            rdfWriter.EndOutput();

            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("wtf", "RDF", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"), "RDF element uses registered prefix");
            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("wtf", "Description", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"), "Description element uses registered prefix");
            Assert.IsTrue(xmlWriter.WasWriteStartAttributeCalledWith("wtf", "about", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"), "about attribute uses registered prefix");
            Assert.IsTrue(xmlWriter.WasWriteStartAttributeCalledWith("wtf", "resource", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"), "resource attribute uses registered prefix");
        }
Ejemplo n.º 14
0
        public void commonNamespacePrefixesAlreadyRegistered()
        {
            XmlWriterStore xmlWriter = new XmlWriterStore();
            RdfXmlWriter   rdfWriter = new RdfXmlWriter(xmlWriter);

            rdfWriter.StartOutput();
            rdfWriter.StartSubject();
            rdfWriter.WriteUriRef("http://example.com/subj");
            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://xmlns.com/foaf/0.1/prop");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();

            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://xmlns.com/wot/0.1/prop");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();

            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#prop");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();

            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://www.w3.org/2000/01/rdf-schema#prop");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();

            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://www.w3.org/2002/07/owl#prop");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();

            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://purl.org/vocab/bio/0.1/prop");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();

            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://purl.org/dc/elements/1.1/prop");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();

            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://purl.org/dc/terms/prop");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();

            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://web.resource.org/cc/prop");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();

            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://purl.org/vocab/relationship/prop");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();


            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://www.w3.org/2003/01/geo/wgs84_pos#prop");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();

            rdfWriter.StartPredicate();
            rdfWriter.WriteUriRef("http://purl.org/rss/1.0/prop");
            rdfWriter.StartObject();
            rdfWriter.WriteUriRef("http://example.com/obj");
            rdfWriter.EndObject();
            rdfWriter.EndPredicate();

            rdfWriter.EndSubject();
            rdfWriter.EndOutput();

            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("foaf", "prop", "http://xmlns.com/foaf/0.1/"), "foaf prefix");
            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("wot", "prop", "http://xmlns.com/wot/0.1/"), "wot prefix");
            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("rdf", "prop", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"), "rdf prefix");
            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("rdfs", "prop", "http://www.w3.org/2000/01/rdf-schema#"), "rdf schema prefix");
            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("owl", "prop", "http://www.w3.org/2002/07/owl#"), "owl prefix");
            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("bio", "prop", "http://purl.org/vocab/bio/0.1/"), "bio prefix");
            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("dc", "prop", "http://purl.org/dc/elements/1.1/"), "dublin core prefix");
            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("dct", "prop", "http://purl.org/dc/terms/"), "dublin core terms prefix");
            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("cc", "prop", "http://web.resource.org/cc/"), "creative commons prefix");
            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("rel", "prop", "http://purl.org/vocab/relationship/"), "relationship prefix");
            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("geo", "prop", "http://www.w3.org/2003/01/geo/wgs84_pos#"), "geo prefix");
            Assert.IsTrue(xmlWriter.WasWriteStartElementCalledWith("rss", "prop", "http://purl.org/rss/1.0/"), "rss prefix");
        }