From: Rob V. <rv...@do...> - 2010-04-08 11:04:23
|
Hi Alexander First off neither of these things are bugs, you appear to be using the CreateLiteralNode() method incorrectly and expecting the ToString() method to work differently from how it is implemented. 1. ToString() is only intended to show a quick view of the value, it does not output the value in an actual RDF syntax it just shows a raw view of the value. ToString() does not add any quotes around values 2. new Uri("xsd:dateTime") does not actually do what you are expecting it to do, xsd:dateTime as seen in much real world RDF is the QName for the full URI http://www.w3.org/2001/XMLSchema#dateTime Your issue is that xsd:dateTime is also a valid URI so when you do new URI("xsd:dateTime") you get the URI "xsd:dateTime" rather than "http://www.w3.org/2001/XMLSchema#dateTime" which is what you are intending. If you have a variable of type DateTime you can actually use the ToLiteral() extension method which turns a DateTime into a LiteralNode in the given Graph like so: DateTime temp = DateTime.Now; Graph g = new Graph(); LiteralNode myDate = temp.ToLiteral(g); There are ToLiteral() extension methods defined for a whole range of primitive .Net types which map to XML Schema Datatypes which turn them into typed LiteralNode's and automatically add the appropriate datatype URI. See http://www.dotnetrdf.org/api/index.asp?topic=VDS.RDF.LiteralExtensions Hope this helps Rob From: Alexander Sidorov [mailto:ale...@gm...] Sent: 04 April 2010 18:21 To: dot...@li... Subject: [dotNetRDF-develop] Graph.CreateLiteralNode bug Hello! I'm using Graph class CreateLiteralNode method overload that has datatype parameter and I think there is a small bug. For example this call: graph.CreateLiteralNode(creationDateTime, new Uri("xsd:dateTime")) will return 2010-04-04T16:41:19+07:00^^xsd:dateTime but should return "2010-04-04T16:41:19+07:00"^^xsd:dateTime. First, I workarounded it this way: graph.CreateLiteralNode(String.Format("\"{0}\"", creationDateTime), new Uri("xsd:dateTime")) but it doesn't work as LiteralNode's ToString method puts the whole string inside one more pair of quotes. Regards, Alexander |