0

JDOM2 でサイトマップとそのインデックスを生成しています。

私が取得したいのはこれです:

<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>http://

そのため、「xmlns」というタイトルのルート要素に属性を追加しました。コードを実行すると、次のエラーが表示されます。

The name "xmlns" is not legal for JDOM/XML attributes: An Attribute name may not be "xmlns"; use the Namespace class to manage namespaces.

上記の構造を変更せずに必要なものを取得するにはどうすればよいですか? ありがとう!

4

1 に答える 1

1

属性ではなく、名前空間を使用する必要があります。

Element root = new Element("sitemapindex", "http://www.sitemaps.org/schemas/sitemap/0.9");

名前空間について読んでください....: http://www.w3schools.com/xml/xml_namespaces.asp

ロルフ

于 2013-01-14T23:57:10.083 に答える