将类打印到文件java/HTA
我有以下HTML文本:将类打印到文件java/HTA,java,asp-classic,printing-web-page,Java,Asp Classic,Printing Web Page,我有以下HTML文本: <table id="items"> <tr> <th>Item</th> <th>Description</th> <th>Unit Cost</th> <th>Quantity</th> <th>Price</th> </tr> <tr class="ite
<table id="items">
<tr>
<th>Item</th>
<th>Description</th>
<th>Unit Cost</th>
<th>Quantity</th>
<th>Price</th>
</tr>
<tr class="item-row">
<td class="item-name"><div class="delete-wpr"><textarea>Items to list</textarea><a class="delete" href="javascript:;" title="Remove row">X</a></div></td>
<td class="description"><textarea>Details about the items</textarea></td>
<td><textarea class="cost">value of the listed item</textarea></td>
<td><textarea class="qty">1</textarea></td>
<td><span class="price">amount total</span></td>
</tr>
项目
描述
单位成本
量
价格
要列出的项目
有关物品的详情
所列项目的价值
1.
总数
我想将表中的结果打印到txt文件中。 我知道这很简单,但我不太擅长java。但我需要弄清楚它在房子周围的一个项目中使用
任何帮助都会很好查看解析代码
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.*;
public class ParseXML {
public static void main(String argv[])throws IOException {
try {
BufferedWriter writer = new BufferedWriter(new FileWriter("results/yourresult.txt"));
File fXmlFile = new File("data/yourxml.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
NodeList nList = doc.getElementsByTagName("md:record");
for (int i = 0; i < nList.getLength(); i++)
{
Node node = nList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE)
{
Element eElement = (Element) node;
if(eElement.hasChildNodes())
{
NodeList nl = node.getChildNodes();
for(int j=0; j<nl.getLength(); j++)
{
Node nd = nl.item(j);
String name= nd.getTextContent();
f (name != null && !name.trim().equals("")) {
System.out.print(name.trim()+",");
//System.out.print(" ");
writer.write(nd.getTextContent().trim() + " ");
}
}
System.out.println("");
writer.write("\n");
}
} }
writer.close();
}
catch (Exception e) {
e.printStackTrace(); } }
@SuppressWarnings("unused")
private static String getTagValue(String sTag, Element eElement)
{
NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes();
Node nValue = (Node) nlList.item(0);
return nValue.getNodeValue();
}
import javax.xml.parsers.DocumentBuilder;
导入org.w3c.dom.Document;
导入org.w3c.dom.NodeList;
导入org.w3c.dom.Node;
导入org.w3c.dom.Element;
导入java.io.*;
公共类解析XML{
公共静态void main(字符串argv[])引发IOException{
试试{
BufferedWriter=newbufferedwriter(newfilewriter(“results/yoursult.txt”);
File fXmlFile=新文件(“data/yourxml.xml”);
DocumentBuilderFactory dbFactory=DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder=dbFactory.newDocumentBuilder();
documentdoc=dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
NodeList nList=doc.getElementsByTagName(“md:record”);
对于(int i=0;i for(int j=0;jWelcome to StackOverflow!到目前为止您尝试了什么?请阅读,不要太迂腐,但这里的内容不是“代码”。而是标记。您需要自己尝试一下,然后才能期待更多帮助。您的“问题”太宽泛了,无法回答。请澄清:您的投入是什么,您希望产生什么样的产出,以及到目前为止您尝试了什么?