我正在尝试用XML解析CDATA tpyes.代码运行正常,它将打印链接:在控制台中(大约50次,因为这是我有多少链接)但链接不会出现......它只是一个空白的控制台空间.我能错过什么?``
package Parse;
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class XMLParse {
public static void main(String[] args) throws Exception {
File file = new File("c:test/returnfeed.xml");
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(file);
NodeList nodes = doc.getElementsByTagName("video");
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
NodeList title = element.getElementsByTagName("videoURL");
Element line = (Element) title.item(0);
System.out.println("Links: " + getCharacterDataFromElement(line));
}
}
public …Run Code Online (Sandbox Code Playgroud) 因此,我编写了一些 JavaScript 来从我的桌面获取一个 xml 文件并将其显示在一个 html 页面上。但是,我现在已将我的 xml 文件添加到网络服务器(猫鼬)。我想从该服务器调用该文件,但是每当我从服务器调用该文件时,它都不起作用,但是当我从桌面调用它时,它加载得很好。
我想换
xmlhttp.open("GET","Devices.xml",false);
Run Code Online (Sandbox Code Playgroud)
和
xmlhttp.open("GET","http://localhost:8080/Devices.xml",false);
Run Code Online (Sandbox Code Playgroud)
这是代码
<html>
<head>
<script type="text/javascript">
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","Devices.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
// the <Device> list
x = xmlDoc.getElementsByTagName('Device');
// make a function that extracts the attributes out of a Node
function getDeviceAttributes(dvc) {
var name = dvc.getAttribute("name");
var uuid = dvc.getAttribute("uuid");
var id = dvc.getAttribute("id");
return "<p>name: " …Run Code Online (Sandbox Code Playgroud) 我正处于无法使用python 2.7并坚持使用2.4.3的情况.我原本试图使用str.format方法,但现在我正在尝试使用%modulo来支持端口.
原始2.7代码:
LINE = "{:<6} {:34} {:18} {:10} {:10} {:10} {:10} {:10}\n"
def main():
with open(OUTPUT, "w") as outf:
outf.write(LINE.format("SysNum", "Job Name", "Target Machiene", "Status", "Start Date", "Start Time", "End Date", "End Time"))
for result in parse_jobfile(INPUT):
outf.write(LINE.format(*result))
Run Code Online (Sandbox Code Playgroud)
需要后端移植的2.4.3代码:
LINE = "{:<6} {:34} {:18} {:10} {:10} {:10} {:10} {:10}\n"
def main():
outf = open(OUTPUT, "w")
outf.write(LINE.'%s, %s,%s, %s,%s, %s,%s, %s,' % ("SysNum", "Job Name", "Target Machiene", "Status", "Start Date", "Start Time", "End Date", "End Time"))
for result in parse_jobfile(INPUT): …Run Code Online (Sandbox Code Playgroud)