JavaでDOMに問題があります...XMLコードは次のとおりです。
<?xml version="1.0" encoding="UTF-8"?>
<bib>
<domain>
<title>Specifications</title>
<bib_ref>
<year>March 2000</year>
<title>MOF 1.3</title>
<author>OMG</author>
<weblink>D:\SALIM\Docs\Specifications\MOF1_3.pdf</weblink>
</bib_ref>
<bib_ref>
<year>August 2002</year>
<title>IDLto Java LanguageMapping Specification</title>
<author>OMG</author>
<weblink>D:\SALIM\Docs\Specifications\IDL2Java.pdf</weblink>
</bib_ref>
<bib_ref>
<year>1999</year>
<title>XML Metadata Interchange (XMI) Version 1.1</title>
<author>OMG</author>
<weblink>D:\SALIM\Docs\Specifications\xmi-1.1.pdf</weblink>
</bib_ref>
<bib_ref>
<year>2002</year>
<title>XML Metadata Interchange (XMI) Version 2</title>
<author>"OMG</author>
<weblink>D:\SALIM\Docs\Specifications\XMI2.pdf</weblink>
</bib_ref>
<bib_ref>
<year>2002</year>
<title>XMI Version 1Production of XML Schema Specification</title>
<author>OMG</author>
<weblink>D:\SALIM\Docs\Specifications\XMI1XSD.pdf</weblink>
</bib_ref>
<bib_ref>
<year>2002</year>
<title>EDOC</title>
<author>OMG</author>
<weblink>D:\SALIM\Docs\Specifications\EDOC02-02-05.pdf</weblink>
</bib_ref>
</domain>
<domain>
<title>Theses</title>
<bib_ref>
<year>Octobre 2001</year>
<title>Echanges de Spécifications Hétérogènes et Réparties</title>
<author>Xavier Blanc</author>
<weblink>D:\SALIM\Docs\Theses\TheseXavier.pdf</weblink>
</bib_ref>
<bib_ref>
<year>Janvier 2001</year>
<title>Composition of Object-Oriented Software Design Models</title>
<author>Siobhan Clarke</author>
<weblink>D:\SALIM\Docs\Theses\SClarkeThesis.pdf</weblink>
</bib_ref>
......
......
その後、Javaのmain関数で、そこにあるdispContent関数を呼び出します。
public void dispContent (Node n)
{
String domainName = null;
// we are in an element node
if (n instanceof Element) {
Element e = ((Element) n);
// domain title
if (e.getTagName().equals("title") && e.getParentNode().getNodeName().equals("domain")) {
domainName = e.getTextContent();
DomaineTemplate(domainName);
}
else if (e.getTagName().equals("bib_ref")) {
NodeList ref = e.getChildNodes();
for (int i = 0; i < ref.getLength(); i++) {
Node temp = (Node) ref.item(i);
if (temp.getNodeType() == Node.ELEMENT_NODE) {
if (temp.getNodeType() == org.w3c.dom.Node.TEXT_NODE)
continue;
out.println(temp.getNodeName() + " : " + temp.getTextContent() + "\n");
}
}
}
else {
NodeList sub = n.getChildNodes();
for(int i=0; (i < sub.getLength()); i++)
dispContent(sub.item(i));
}
}
/*else if (n instanceof Document) {
NodeList fils = n.getChildNodes();
for(int i=0; (i < fils.getLength()); i++) {
dispContent(fils.item(i));
}
}*/
}
「domaineTemplate」関数はそのパラメータを表示するだけです!Javaで「bib_ref」タグを参照すると問題が発生します。「bib_ref」ループごとに、すべての「bib_ref」タグのすべての内容が1行に表示されます。「bib_ref」ごとに1つのコンテンツ(年、タイトル、作成者、およびWebリンクタグ)のみを表示したい。
これが、bib_refを参照したときに表示されているものです。
仕様
年:2000年3月タイトル:MOF 1.3作成者:OMG Webリンク:D:\ SALIM \ Docs \ Specifications \ MOF1_3.pdf年:2002年8月タイトル:IDLto Java LanguageMapping仕様作成者:OMG Webリンク:D:\ SALIM \ Docs \ Specifications \ IDL2Java .pdf年:1999タイトル:XMLメタデータインターチェンジ(XMI)バージョン1.1作成者:OMG Webリンク:D:\ SALIM \ Docs \ Specifications \ xmi-1.1.pdf年:2002タイトル:XMLメタデータインターチェンジ(XMI)バージョン2作成者:OMG weblink:D:\ SALIM \ Docs \ Specifications \ XMI2.pdf年:2002タイトル:XMIバージョン1 XMLスキーマ仕様の作成作成者:OMG weblink:D:\ SALIM \ Docs \ Specifications \ XMI1XSD.pdf年:2002タイトル:EDOC作成者:OMG Webリンク:D:\ SALIM \ Docs \ Specifications \ EDOC02-02-05.pdf
論文
年:Octobre 2001タイトル:EchangesdeSp�cificationsH�t�rog�nesetR�parties著者:Xavier Blancウェブリンク:D:\ SALIM \ Docs \ theses \ theseXavier.pdf年:Janvier 2001タイトル:オブジェクトの構成- Oriented Software Design Models作成者:Siobhan Clarke Webリンク:D:\ SALIM \ Docs \ theses \ SClarkeThesis.pdf年:2002年7月タイトル:寄稿ウェブリンク:D:\ SALIM \ Docs \ Thiss \ ErwanBretonThesis.pdf年:Octobre 2000タイトル:TechniquedeMod�lisationetdeM�tamod�lisation作者:Richard Lemesleウェブリンク:D:\ SALIM \ Docs \ theses\RichardLemesle。 pdf年:Juillet 2002タイトル:Utilsation d'agents mobiles pour la Construction des services distribu�sauthor:Siegfried Rouvrais weblink:D:\ SALIM \ Docs \ theses \ theserouvrais.pdf ... .. ..
手伝って頂けますか ?私はJavaを使用したxmlの初心者であり、約3時間ソリューションを探しています...どうもありがとうございました!