thisページを通過した後、XSDファイルを解析する次のコードを書きました。しかし、私はルート要素だけを取得し、内部に入れ子要素を取得する方法は失われてしまいます。 コード:XSDの解析とネストされた要素の取得
XMLSchemaLoader loader = new XMLSchemaLoader();
XSModel model = loader.loadURI(url.toURI().toString());
XSNamedMap map = model.getComponents(XSConstants.ELEMENT_DECLARATION); //returns the root component
if(map!=null){
for (int j=0; j<map.getLength(); j++) {
String name = map.item(j).getName(); //returns 'country' correctly.
}
}
私は全体のxsdを投稿していないのですが、これは構造体である:
<xsd:element name="country">
<xsd:complexType>
<xsd:annotation>
<xsd:appinfo id="substring">No</xsd:appinfo>
</xsd:annotation>
<xsd:sequence minOccurs="1" maxOccurs="unbounded">
<xsd:element name="states" minOccurs="1" maxOccurs="1" >
<xsd:complexType>
<xsd:annotation>
<xsd:appinfo id="substring">No</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="cities" minOccurs="1" maxOccurs="unbounded">
</xsd:element>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string"></xsd:attribute>
</xsd:complexType>
</xsd:element>
私はすべての要素だけでなく、基本要素を読み取るために探していますし、方法がわかりません続行します。助けてくれてありがとう。
ユーザーは、タイトルではなくタグでブラウズします。タイトルのメインタグ '[java]'を繰り返す必要はなく、[Javaの質問の一覧](http://stackoverflow.com/questions/tagged/java)全体が乱雑になるだけです。 – BalusC
訂正ありがとう! – rgamber