如何获得"prensentationURL"从XML页面与Java? [英] How to get "prensentationURL" from XML Page with Java?
本文介绍了如何获得"prensentationURL"从XML页面与Java?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从XML页面获取presentationURL.我可以通过以下方式获取位置网址:
I'm trying to get presentationURL from an XML page. I can get the location URL with:
public String getLocation()
{
return HTTPHeader.getValue(getData(), HTTP.LOCATION);
}
但这不是我想要的.我得到的网址将我带到文档树.我想要的是在此树中获取"presentationURL"变量.
but it's not the exactly what I want. Url I get takes me to a document tree. What I want is to get "presentationURL" variable in this tree.
推荐答案
类似这样.对于您的结构,这是最简便的方法. 您使用XMLStreamReader通过字符串读取xml并通过名称检查开始\结束元素.
Some like this. It is a fasest and simple method for your structure. You using XMLStreamReader to read xml by strings and check start\end elemens by name.
StringBuffer xml = new StringBuffer(
"<note>\n" +
"<to>Tove</to>" +
"<from>Jani</from>" +
"<heading>" +
"<prensentationURL>maValue</prensentationURL>" +
"</heading>" +
"<body>any any</body>" +
"</note>");
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new ByteArrayInputStream(xml.toString().getBytes()));
String prensentationURL = null;
while (streamReader.hasNext()) {
streamReader.next();
String name = null;
if (streamReader.isStartElement()) {
if ("prensentationURL".equals(streamReader.getLocalName())) {
prensentationURL = streamReader.getElementText();
}
}
if (streamReader.isEndElement() && streamReader.getLocalName().equals("prensentationURL")) break;
}
System.out.println(prensentationURL);
这篇关于如何获得"prensentationURL"从XML页面与Java?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文