如何从 XML java 中的标签内部获取图像的 link
How can I get the link of an image from inside the tag in XML java
我正在尝试读取 XML 文件并将标签之间的值存储为字符串。但是对于一个标签 <picture url="https://cloudstor.aarnet.edu.au/plus/s/62e0uExNviPanZE/download"/>
我需要获取图像的 URL 并存储它以便将来使用它。
我用了
File stocks = new File("gui.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
dbFactory.setIgnoringElementContentWhitespace(true);
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(stocks);
doc.getDocumentElement().normalize();
System.out.println("root of xml file" + doc.getDocumentElement().getNodeName());
NodeList nodes = doc.getElementsByTagName("billboard");
System.out.println("==========================");
Node node = nodes.item(0);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
//message = getValue("message", element);
information = getValue("information", element).trim();
String picture = getValue("picture url=", element);
}
private static String getValue(String tag, Element element) {
NodeList nodes = element.getElementsByTagName(tag).item(0).getChildNodes();
Node node = (Node) nodes.item(0);
return node.getNodeValue();
}
这适用于从普通标签中获取信息,例如此处的信息标签。知道如何让它适用于图片标签吗?
<billboard class="nodarken">
<information>
Billboard with an information tag and nothing else. Note that the text is word-wrapped. The quick brown fox jumped over the lazy dogs.
</information>
<picture url="https://cloudstor.aarnet.edu.au/plus/s/62e0uExNviPanZE/download"/>
</billboard>
使用<link><![CDATA[ your url goes here ]]></link>
这种格式
<billboard class="nodarken">
<information>
Billboard with an information tag and nothing else. Note that the text is word-wrapped. The quick brown fox jumped over the lazy dogs.
</information>
<picture><![CDATA[ https://cloudstor.aarnet.edu.au/plus/s/62e0uExNviPanZE/download"]]></picture>
</billboard>
我正在尝试读取 XML 文件并将标签之间的值存储为字符串。但是对于一个标签 <picture url="https://cloudstor.aarnet.edu.au/plus/s/62e0uExNviPanZE/download"/>
我需要获取图像的 URL 并存储它以便将来使用它。
我用了
File stocks = new File("gui.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
dbFactory.setIgnoringElementContentWhitespace(true);
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(stocks);
doc.getDocumentElement().normalize();
System.out.println("root of xml file" + doc.getDocumentElement().getNodeName());
NodeList nodes = doc.getElementsByTagName("billboard");
System.out.println("==========================");
Node node = nodes.item(0);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
//message = getValue("message", element);
information = getValue("information", element).trim();
String picture = getValue("picture url=", element);
}
private static String getValue(String tag, Element element) {
NodeList nodes = element.getElementsByTagName(tag).item(0).getChildNodes();
Node node = (Node) nodes.item(0);
return node.getNodeValue();
}
这适用于从普通标签中获取信息,例如此处的信息标签。知道如何让它适用于图片标签吗?
<billboard class="nodarken">
<information>
Billboard with an information tag and nothing else. Note that the text is word-wrapped. The quick brown fox jumped over the lazy dogs.
</information>
<picture url="https://cloudstor.aarnet.edu.au/plus/s/62e0uExNviPanZE/download"/>
</billboard>
使用<link><![CDATA[ your url goes here ]]></link>
这种格式
<billboard class="nodarken">
<information>
Billboard with an information tag and nothing else. Note that the text is word-wrapped. The quick brown fox jumped over the lazy dogs.
</information>
<picture><![CDATA[ https://cloudstor.aarnet.edu.au/plus/s/62e0uExNviPanZE/download"]]></picture>
</billboard>