题
我有这样的代码:
[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;
}
这种方式创建的:
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());
下面是结果的一部分:
<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>
首先的问题是:我如何才能让和为单个标签
第二个问题:我如何才能让标签不可见,但只有它的内容?即所有子是标记的直接子。
解决方案
在短:你想要什么违反RDF规范。它看起来像你想治疗输出格式为XML,但你不应该!
在RDF,你操纵的三倍,你永远也不会关心它是如何序列化为XML,RDF因为语法是独立的,RDF / XML序列化规范允许代表相同的三元组集合许多不同的方式。为了说明它,你可以选择RDF工具“A”创建一个RDF文件。你挑RDF工具“B”,加载该文件,并再次将其保存为新名称没有任何修饰。您比较的两个文件,你会发现里面的相同三元但两个XML文件看起来可能完全不同!你不能让标签来来去去,竟标签是“不是你的业务” :)。
在底线是,如果你要决定你的输出XML应该什么样子,你应该完全忘记RDF,只需使用普通的旧XML工具来完成工作做好。
不隶属于 StackOverflow