-2
XML文字列から属性名と値を読み取るコードを作成していますが、私のノードはたとえばhi:collectionとして表されているため、エラープレフィックスが見つかりませんURL:こんにちはVTD-XMLを使用して属性名と値を取得する
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPathExpressionException;
import com.ximpleware.*;
import org.xml.sax.SAXException;
public class A20 {
public static void main(String[] args) throws IOException, XPathExpressionException, ParserConfigurationException, SAXException, XPathParseException, XPathEvalException, NavException{
URL a=new URL("URL");
HttpURLConnection b=(HttpURLConnection) a.openConnection();
b.setRequestMethod("GET");
b.setRequestProperty("Accept", "application/xml");
BufferedReader c=new BufferedReader(new InputStreamReader(b.getInputStream()));
StringBuilder sb=new StringBuilder();
String out,out1 = null;
while((out=c.readLine())!=null)
{sb.append(out);
out1=sb.toString();
System.out.println(out1); }
c.close();
b.disconnect();
byte[] bytes = out1.getBytes("UTF-8");
VTDGen vg = new VTDGen();
vg.setDoc(bytes);
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("//hi:collection/@name");// I am getting error here
int i=0;
while((i=ap.evalXPath())!=-1){
System.out.println(" item name is ===>"+vn.toString(i+1));
}
}
}