Question

I have this code:

   [RdfSerializable( HasResourceUri=false )]
   public class Item
   {
      [RdfProperty(true)]
      public string MyProp;
   }

   [RdfSerializable]
   public class AllItems
   {
      [RdfProperty(true)] public string mTitle;

      private int id = new Random().Next(0, 20);

      [ResourceUri]
      public string ResourceUri 
      {
         get { return "This " + id.ToString(); }
      }

      [RdfProperty(false, Name="item")]
      public Item[] Items;
   }

Created this way:

var item = new AllItems();
item.mTitle = "Hello World!";
item.Items = new Item[] { new Item() { MyProp = "test1" }, new Item() { MyProp = "test2" } };

var doc = Rdfizer.Serialize(item);

System.Console.Out.Write(doc.ToString());

Here is a part of the result:

         <ns:AllItems rdf:about="This 1">
                <ns:mTitle rdf:datatype="http://www.w3.org/2001/XMLSchema#string
">Hello World!</ns:mTitle>
                <ns:item>
                        <ns:Item>
                                <ns:MyProp rdf:datatype="http://www.w3.org/2001/
XMLSchema#string">test1</ns:MyProp>
                        </ns:Item>
                </ns:item>
                <ns:item>
                        <ns:Item>
                                <ns:MyProp rdf:datatype="http://www.w3.org/2001/
XMLSchema#string">test2</ns:MyProp>
                        </ns:Item>
                </ns:item>
        </ns:AllItems>

First question is: How could I make and be a single tag?

Second question: How could I make tag not visible, but only its content? i.e. all of its children to be direct children of tag.

Was it helpful?

Solution

In short: what you want violates RDF specs. It looks like you would like to treat the output as XML, but you shouldn't!

In RDF, you manipulate the triples and you should never ever care how it is serialized into XML, because RDF is syntax independent and RDF/XML serialization specs allows to represent the same set of triples many different way. To illustrate it, you might pick RDF Tool "A" create an RDF document. You pick RDF Tool "B", load that document and save it under a new name again without any modification. You compare the two files and you will find the same triples inside but the two XML files might look quite different! You cannot make tags come and go, actually tags are "not your business" :).

The bottomline is, if you want to dictate how your output XML should look like, you should just forget RDF completely and just use plain old XML tools to do get the job done.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top