C# xml压缩包不解压的情况下解析xml内容

 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;
}
}
}
}
上一篇:微信机器人11python自制微信机器人,定时发送天气预报


下一篇:吐槽微信开发者工具