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"); }
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/")); }
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/")); }
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"); }
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"); }
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/")); }
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"); }
public void writerWritesOneRdfDescriptionPerUniqueSubject() { XmlWriterCounter xmlWriter = new XmlWriterCounter(); RdfXmlWriter rdfWriter = new RdfXmlWriter(xmlWriter); rdfWriter.StartOutput(); rdfWriter.StartSubject(); rdfWriter.WriteUriRef("http://example.com/subj"); rdfWriter.StartPredicate(); rdfWriter.WriteUriRef("http://example.com/pred"); rdfWriter.StartObject(); rdfWriter.WriteUriRef("http://example.com/obj"); rdfWriter.EndObject(); rdfWriter.EndPredicate(); rdfWriter.EndSubject(); rdfWriter.StartSubject(); rdfWriter.WriteUriRef("http://example.com/subj2"); rdfWriter.StartPredicate(); rdfWriter.WriteUriRef("http://example.com/pred"); rdfWriter.StartObject(); rdfWriter.WriteUriRef("http://example.com/obj"); rdfWriter.EndObject(); rdfWriter.EndPredicate(); rdfWriter.EndSubject(); rdfWriter.StartSubject(); rdfWriter.WriteUriRef("http://example.com/subj"); rdfWriter.StartPredicate(); rdfWriter.WriteUriRef("http://example.com/pred"); rdfWriter.StartObject(); rdfWriter.WriteUriRef("http://example.com/obj2"); rdfWriter.EndObject(); rdfWriter.EndPredicate(); rdfWriter.EndSubject(); rdfWriter.EndOutput(); // elements should be: rdf:RDF, rdf:Description * 2, ns1:pred * 3 Assert.AreEqual(6, xmlWriter.WriteEndElementCalled); }
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"); }