ROWLEX 中一个属性的双重标签
我有这样的代码:
[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>
第一个问题是:我如何制作并成为单个标签?
第二个问题:如何使标签不可见,而仅显示其内容? 即它的所有子代都是标签的直接子代。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简而言之:您想要的内容违反了 RDF 规范。 您似乎希望将输出视为 XML,但您不应该这样做!
在 RDF 中,您可以操作三元组,而不必关心它如何序列化为 XML,因为 RDF 与语法无关,并且 RDF/XML 序列化规范允许以多种不同的方式表示同一组三元组。 为了说明这一点,您可以选择 RDF 工具“A”创建一个 RDF 文档。 您选择 RDF 工具“B”,加载该文档并再次以新名称保存,无需任何修改。 比较这两个文件,您会发现里面有相同的三元组,但两个 XML 文件可能看起来完全不同! 你不能让标签来来去去,实际上标签“不关你的事”:)。
底线是,如果您想要指定输出 XML 的外观,您应该完全忘记 RDF,而只使用简单的旧式 XML 工具来完成工作。
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.