私の目的は、XMLファイルを読み込み、(技術的ではない)ユーザーがこのファイルを変更できるようにする簡単なインターフェイスを提供することです。 xmlファイルはFlashフォトギャラリーを駆動し、そのFlash Actionscriptによってあらかじめ定義されています。JavaでXMLファイルを読み込み、Element属性を取得する際に問題が発生する
XMLのサンプルが...これらは、ギャラリーで表示される写真のそれぞれを定義するので、複数の写真のノードが存在することができ、今
このXMLで
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<photostack3d>
<photos>
<photo>
<thumb src="Thumbs/bed1.jpg"/>
<img src="Photos/bed1.jpg"/>
<caption text="Master Bedroom"/>
<desc><![CDATA[<h1>Master Bedroom</h1><br>The master bedroom is roomy and has a beautiful view of the landscaped back yard.]]></desc>
</photo>
</photos>
</photostack3d>
です私はDOMを使用してファイルを作成しているので、そこにはうまくいきます。 DOMを使用してそれをさらに編集するために試してみることは、私が問題にぶつかるところです。私はすべての写真要素に行くことができますが、サム、img、キャプション、descなどの属性に問題があります。現在、私は次のようしている:あなたが見ることができるように
private void loadXML(String filePath)
{
try
{
File fXmlFile = new File(filePath);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
NodeList photosList = doc.getElementsByTagName("photos");
System.out.println("-----------------------");
NodeList photoList = doc.getElementsByTagName("photo");
System.out.println("Number of photo nodes: " + photoList.getLength());
for (int temp = 0; temp < photoList.getLength(); temp++)
{
NodeList thumbList = doc.getElementsByTagName("thumb");
Element thumbElement = (Element) thumbList.item(0);
String thumbName = thumbElement.getAttribute("thumb");
System.out.println("thumb name: " + thumbName);
//Node nNode = photoList.item(temp);
//if (nNode.getNodeType() == Node.ELEMENT_NODE)
//{
// Element eElement = (Element) nNode;
// System.out.println("Source Name : " + eElement.getAttribute("text")); //.getElementsByTagName("thumb"));
//System.out.println("Source Name : " + getTagValue("thumb", eElement));
System.out.println("-----------------------");
//}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
を、私はそれらの属性で取得するために、様々な異なる方法をしようとしてきたが、まだのように、単に値が戻って来て見ません。どこが間違っていますか?
親指、imgなどは要素です。 srcはサム要素/ img要素の属性です。 – Jayan