有没有人知道如何在深度优先遍历中跟踪xsd中的路径 例如:如果我有这个架构,
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:books" xmlns:bks="urn:books">
<xsd:element name="books" type="bks:BooksForm"/>
<xsd:complexType name="BooksForm">
<xsd:sequence>
<xsd:element name="book" type="bks:BookForm" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="BookForm">
<xsd:sequence>
<xsd:element name="author" type="xsd:string"/>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="genre" type="xsd:string"/>
<xsd:element name="price" type="xsd:float" />
<xsd:element name="pub_date" type="xsd:date" />
<xsd:element name="review" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string"/>
</xsd:complexType>
</xsd:schema>
如何在c#
中获得此输出path1 : books.book.author
path2 : books.book.title
..等等
用于任何架构结构
有没有人对这个或任何好的起点有所了解 提前谢谢
感谢您的回复 我试着编写你的建议,但我仍然陷入困境
while (r.Read())
{
switch (r.Name)
{
case "xsd:element":
myStringBuilder.Append(r.GetAttribute("name"));
break;
case "xsd:complexType":
checkComplex(r);
wholepath += r.GetAttribute("name");
//this will only concatenate complex elements only
Console.WriteLine("checkComplexcaller{1}", wholepath);
break;
}
}
用于递归部分..我做了
public static void checkComplex(/*what I should send here*/)
{
if (r.GetAttribute("name") == "xsd:complexType")
{
//What I sould to do for this recursive
}
else if (r.GetAttribute("name") == "xsd:element")
{
myStringBuilder.Append(r.GetAttribute("name"));
}
}
如何正确设置路径
答案 0 :(得分:0)
如果我做对了:(伪代码)
(make a xml document of the xsd)
foreach node of type xsd:element:
track path to the node as input
apend it with values of 'name' and 'type' attributes
if its a complex type: apply this recursively on all elements