我有这样的代码:
[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>第一个问题是:我怎样才能成为一个单独的标签?
第二个问题:如何使标签不可见,而只显示其内容?即它的所有子代都是标签的直接子代。
发布于 2009-07-16 15:30:38
简而言之:您想要的东西违反了RDF规范。看起来您希望将输出视为XML,但您不应该这样做!
在RDF中,您操作三元组,并且永远不应该关心如何将其序列化为XML,因为RDF是独立于语法的,并且RDF/XML序列化规范允许以许多不同的方式表示同一组三元组。为了说明这一点,您可以选择RDF工具"A“创建一个RDF文档。您选择RDF工具"B",加载该文档并以新名称再次保存它,而不做任何修改。比较这两个文件,您会发现里面有相同的三元组,但两个XML文件看起来可能完全不同!你不能让标签来来去去,实际上标签“不关你的事”:)。
底线是,如果您想指定输出XML应该是什么样子,就应该完全忘记RDF,只使用普通的老式XML工具来完成这项工作。
https://stackoverflow.com/questions/1134196
复制相似问题