package com.huayingsoft.util;
import java.io.File;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Attr;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
public class XMLHelper {
private Document doc;
public XMLHelper() {
}
/**
* 判断文件扩展名
*
* @param fileNameStr
* 文件名
* @param extendName
* 扩展名
*/
public boolean estimateExtend(String fileNameStr, String extendName) {
int pos = fileNameStr.trim().lastIndexOf(".");
if (pos == -1 || pos == 0 || pos == fileNameStr.trim().length() - 1)
return false;
String extendStr = fileNameStr.trim().substring(pos + 1);
if (extendStr.equalsIgnoreCase(extendName))
return true;
else
return false;
}
/**
* 更改文件扩展名
*
* @param fileNameStr
* 文件名
* @param extendName
* 扩展名
*/
private String changeExtend(String fileNameStr, String extendName) {
int pos = fileNameStr.trim().lastIndexOf(".");
if (pos == -1 || pos == 0)
return fileNameStr;
fileNameStr = fileNameStr.trim().substring(0, pos + 1) + extendName;
return fileNameStr;
}
public String readXmlThreeLayer(String xmlFile, String Xpath,
boolean hasAttr, String[] attrNames) throws Exception {
try {
StringBuilder sb = new StringBuilder();
File f = new File(xmlFile);
if (f.exists()) {
// XmlNodeList list = null;
NodeList list = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory
.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
this.doc = db.parse(f);
String attr = "";
// this.doc = new XmlDocument();
// this.doc.Load(xmlFile);
if (Xpath != null || Xpath.length() > 0) {
XPath xpath = XPathFactory.newInstance().newXPath();
list = (NodeList) xpath.evaluate(Xpath, this.doc,
XPathConstants.NODESET);
// list = this.doc.SelectSingleNode(Xpath).ChildNodes;
} else {
list = this.doc.getDocumentElement().getChildNodes();
}
int lengthTop = list.getLength();
for (int i = 0; i < lengthTop; i++) {
int lengthTwo = list.item(i).getChildNodes().getLength();
for (int j = 0; j < lengthTwo; j++) {
int lengthThree = list.item(i).getChildNodes().item(j)
.getChildNodes().getLength();
if (lengthThree > 1) {
for (int k = 0; k < lengthThree; k++) {
String node = list.item(i).getChildNodes()
.item(j).getChildNodes().item(k)
.getNodeValue();
if (hasAttr)
attr = this.readAttribute(list.item(i)
.getChildNodes().item(j)
.getChildNodes().item(k)
.getAttributes(), attrNames);
if (k != lengthThree - 1) {
// sb.AppendFormat("{0}{1}$", node, attr);
sb.append(node + attr + "$");
} else {
// sb.AppendFormat("{0}{1}", node, attr);
sb.append(node + attr);
}
}
} else if (lengthThree == 1) {
// sb.AppendFormat("{0}",
// list.Item(i).ChildNodes.Item(j).ChildNodes.Item(0).InnerText);
sb.append(list.item(i).getChildNodes().item(j)
.getChildNodes().item(0).getNodeValue());
} else {
// sb.AppendFormat("{0}", list.Item(i).InnerText);
sb.append(list.item(i).getNodeValue());
}
if (hasAttr)
attr = this.readAttribute(list.item(i)
.getChildNodes().item(j).getAttributes(),
attrNames);
if (j != lengthTwo - 1) {
// sb.AppendFormat("{0}#", attr);
sb.append(attr + "#");
} else {
// sb.AppendFormat("{0}", attr);
sb.append(attr);
}
}
if (hasAttr)
attr = this.readAttribute(list.item(i).getAttributes(),
attrNames);
// sb.AppendFormat("{0}|", attr);
sb.append(attr + "|");
}
} else
sb.append("--文件不存在!--");
return sb.toString();
} catch (Exception e) {
throw e;
}
}
public String readXmlThreeLayer(String xmlFile, boolean hasAttr,
String[] attrNames) {
try {
return this.readXmlThreeLayer(xmlFile, "", hasAttr, attrNames);
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
public String readXml(String xmlFile, String pNodePath, String[] nodeNames,
boolean hasAttr, String[] attrNames) throws Exception {
StringBuilder sb = new StringBuilder();
File f = new File(xmlFile);
try {
if (f.exists()) {
Node root = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory
.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
this.doc = db.parse(f);
// this.doc = new XmlDocument();
// this.doc.Load(xmlFile);
if (pNodePath != null && pNodePath.length() > 0) {
XPath xpath = XPathFactory.newInstance().newXPath();
root = (Node) xpath.evaluate(pNodePath, this.doc,
XPathConstants.NODE);
// root = this.doc.SelectSingleNode(pNodePath);
} else
root = this.doc.getDocumentElement();
if (root != null) {
if (root.hasChildNodes()) {
// sb.AppendFormat("{0}",
// this.readChildNode(root.ChildNodes, nodeNames,
// hasAttr, attrNames));
sb.append(this.readChildNode(root.getChildNodes(),
nodeNames, hasAttr, attrNames));
} else {
// sb.AppendFormat("{0}",root.InnerText);
sb.append(root.getNodeValue());
}
} else
sb.append("--节点不存在--");
} else
sb.append("--文件不存在!--");
} catch (Exception e) {
throw e;
}
return sb.toString();
}
public String readXml(String xmlFile, String pNodePath, String[] nodeNames,
boolean hasAttr) {
try {
return this.readXml(xmlFile, pNodePath, nodeNames, hasAttr, null);
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
public String readXml(String xmlFile, String pNodePath, boolean hasAttr)
throws Exception {
StringBuilder sb = new StringBuilder();
File f = new File(xmlFile);
try {
if (f.exists()) {
NodeList root = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory
.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
this.doc = db.parse(f);
// this.doc=new XmlDocument();
// this.doc.Load(xmlFile);
if (pNodePath != null && !pNodePath.equals("")) {
if (!pNodePath.trim().equals("%")) {
// sb.AppendFormat("{0}",this.readXml(xmlFile,pNodePath,null,false,null));
XPath xpath = XPathFactory.newInstance().newXPath();
// XmlNode node=this.doc.SelectSingleNode(pNodePath);
Node node = (Node) xpath.evaluate(pNodePath, this.doc,
XPathConstants.NODE);
if (node != null) {
if (node.hasChildNodes()) {
root = node.getChildNodes();
int len = root.getLength();
for (int p = 0; p < len; p++) {
if (root.item(p).hasChildNodes()) {
int tmp = root.item(p).getChildNodes()
.getLength();
for (int k = 0; k < tmp; k++) {
if (k == tmp - 1) {
String attr1 = "";
if (hasAttr)
attr1 = this
.readAttribute(root
.item(p)
.getAttributes());
// sb.AppendFormat("{0}{1}|",root.Item(p).ChildNodes.Item(k).InnerText,attr1);
sb.append(root.item(p)
.getChildN
没有合适的资源?快使用搜索试试~ 我知道了~
JAVA服装进销存管理系统源码

共1236个文件
class:310个
java:307个
gif:278个

2 下载量 198 浏览量
2023-07-31
18:29:59
上传
评论 1
收藏 29.49MB ZIP 举报
温馨提示
支持会员卡预存充值 采购管理 销售管理 库存管理 数据库使用mysql5 jdk5,6,7以上 eclipse indigo 3.7.2 其他没有什么要求 数据库访问地址配置:数据库连接配置文件:HuayingsoftDataBaseConfig.properties 只需要配置mysql部分的连接即可 HuayingsoftFrameworkConfig.xml模块访问配置,如果是本机可以不用改, 如果是部署到服务器就改为对应域名就可以;
资源推荐
资源详情
资源评论

















收起资源包目录





































































































共 1236 条
- 1
- 2
- 3
- 4
- 5
- 6
- 13
资源评论


大山源码
- 粉丝: 43
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 类 OpenAI 接口适配开源大模型,像用 ChatGPT 一样使用 LLMs!支持 LLaMA、LLaMA-2、BLOOM、Falcon、百川、通义千问、X…
- 单片机的指纹识别系统设计大学课程.doc
- XXX项目软件测试计划.docx
- 电子政务项目管理建设与运行管理对策探析.doc
- 实时时钟日历芯片与单片机的接口电路设计.doc
- 新工科背景下计算机专业应用型人才培养研究.docx
- 基于zigbee技术的智能家居控制系统的设计.docx
- 实例--基于WEB的网络教学评价系统设计与实现.doc
- 单片机温度采集系统设计方案.docx
- 包头市石拐区矿山地质环境治理项目管理实施实施方案书.doc
- 互联网创客教育-生物课堂教学模式的策略研究.docx
- 基于ARM11嵌入式WEB开发环境的搭建.doc
- 大数据思维在高校学生管理工作中的运用探索.docx
- 面向能力培养的计算机基础课程教学改革探析.docx
- 高三一轮作业生物知识结构网络图.doc
- 职称计算机测验考试模拟测验考试(附标准答案).doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
