Does anyone have an idea about how keep track of a paths in xsd in deep-first traverse For example: if I have this schema,
<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>
how can I get like this output in c#
path1 : books.book.author
path2 : books.book.title
.. so on
for any schema structure
does anyone have an idea about this or any good starting points thanks in advance
thanks for reply I tried to code your advice but I am still getting stuck
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;
}
}
for recursive part.. I did
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"));
}
}
How could setup the path correctly
If I am getting this right: (pseudocode)
(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
精彩评论