2011-01-14 118 views
0

有沒有人有關於如何在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

如果我得到這個權利:(僞)

(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 
+0

我試圖代碼什麼也建議我,但我被陷在某些方面 – Dena 2011-01-14 10:06:59