C# xml压缩包不解压的情况下解析xml内容
2024-10-18 11:00:26
string sourceFilePath = @"E:\文件拷贝\xx\3773\3773.zip"; FileInfo fileInfo = new FileInfo(sourceFilePath);
long length = fileInfo.Length; if (length == )
{
return;
} using (ZipInputStream zip = new ZipInputStream(File.OpenRead(sourceFilePath)))
{
ZipEntry theEntry;
string destinationDirPath = @"\\172.21.3.21\liung\";
while ((theEntry = zip.GetNextEntry()) != null)
{
destinationDirPath += theEntry.Name; using (FileStream streamWriter = new FileStream(destinationDirPath, FileMode.Create, FileAccess.Write, FileShare.Read | FileShare.Write))
{
byte[] bytes = new byte[zip.Length];
zip.Read(bytes, , bytes.Length);
streamWriter.Write(bytes, , bytes.Length);
} XmlTextReader xmlReader = new XmlTextReader(zip);
while (xmlReader.Read())
{
if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name.ToLower() == "fileheader")
{
string reportTime = xmlReader.GetAttribute("reportTime").Replace("24:00:00", "23:59:59");
string startTime = xmlReader.GetAttribute("startTime").Replace("24:00:00", "23:59:59");
string endTime = xmlReader.GetAttribute("endTime").Replace("24:00:00", "23:59:59"); break;
}
}
}
} Console.ReadKey(); using (GZipInputStream zip = new GZipInputStream(File.OpenRead(sourceFilePath)))
{
using (XmlTextReader xmlReader = new XmlTextReader(zip))
{
while (xmlReader.Read())
{
// hw没有period,暂时给一个默认值15
if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name.ToLower() == "fileheader")
{
string reportTime = xmlReader.GetAttribute("reportTime").Replace("24:00:00", "23:59:59");
string startTime = xmlReader.GetAttribute("startTime").Replace("24:00:00", "23:59:59");
string endTime = xmlReader.GetAttribute("endTime").Replace("24:00:00", "23:59:59"); break;
}
}
}
}
最新文章
- java substring
- [学习笔记]四边形不等式优化DP
- MongoDB-JAVA-Driver 3.2版本常用代码全整理(2) - 查询
- React和ES6(二)ES6的类和ES7的property initializer
- Centos 6.5(64bit)上安装Vertica single node
- 二、IRIG_B解码AC信号
- IE下判断IE版本的语句...[if lte IE 6]……[endif]
- string和stringbuilder
- 进程识别号(PID)的理解
- Ecshop导航栏标题栏的伪静态设置
- beanutils设置参数和获取参数
- Mysql利用存储过程插入400W条数据
- 原生js简单调用百度翻译API实现的翻译工具
- mysql 开发基础系列14 字符集
- sql 索引笔记
- Centos6.8下编译安装LAMP的操作记录梳理
- 原生App切图的那些事儿
- 针对程序员的podcast
- C#图片处理,缩略图制作
- zTree静态树与动态树的用法——(七)