c# - 如何在 C# 中读取 SVCLOG 文件
问题描述
我需要<ns2:Response>400 or 200 etc</n2:Response>
使用服务跟踪查看器找到标签,它看起来像这样!!
<SOAP-ENV:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-14799">
<ns2:SendInvoice xmlns:ns2="http://www.zadrwan.com/services/" xmlns:ns3="http://www.zadrwan.com/services/DocumentSendTo" xmlns:ns4="http://www.zadrwan.com/services/VersionRequest">
<ns2:Response>200</ns2:Response>
<ns2:Comments>Success!.</ns2:Comments>
</ns2:SendInvoice>
</SOAP-ENV:Body>
或者是否有另一种方法可以在不使用 XML 阅读器(读取所有文档)的情况下获取变量,或者在这种情况下,使用文本阅读器(我正在重新设计使用 a 的 VB 项目StreamReader
)?
解决方案
有很多方法。由于有一个架构,您可以使用 xsd.exe 工具来获取类,我将使用下面的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace ConsoleApplication1
{
class Program
{
const string FILENAME = @"c:\temp\test.xml";
static void Main(string[] args)
{
XmlReader reader = XmlReader.Create(FILENAME);
XmlSerializer serializer = new XmlSerializer(typeof(TimestampType));
TimestampType timeStamp = (TimestampType)serializer.Deserialize(reader);
}
}
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.6421
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
//
// This source code was auto-generated by xsd, Version=2.0.50727.3038.
//
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xs" +
"d")]
[System.Xml.Serialization.XmlRootAttribute("Timestamp", Namespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xs" +
"d", IsNullable=false)]
public partial class TimestampType {
private AttributedDateTime createdField;
private AttributedDateTime expiresField;
private System.Xml.XmlElement[] itemsField;
private string idField;
private System.Xml.XmlAttribute[] anyAttrField;
/// <remarks/>
public AttributedDateTime Created {
get {
return this.createdField;
}
set {
this.createdField = value;
}
}
/// <remarks/>
public AttributedDateTime Expires {
get {
return this.expiresField;
}
set {
this.expiresField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAnyElementAttribute()]
public System.Xml.XmlElement[] Items {
get {
return this.itemsField;
}
set {
this.itemsField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified, DataType="ID")]
public string Id {
get {
return this.idField;
}
set {
this.idField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAnyAttributeAttribute()]
public System.Xml.XmlAttribute[] AnyAttr {
get {
return this.anyAttrField;
}
set {
this.anyAttrField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xs" +
"d")]
[System.Xml.Serialization.XmlRootAttribute("Expires", Namespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xs" +
"d", IsNullable=false)]
public partial class AttributedDateTime {
private string idField;
private System.Xml.XmlAttribute[] anyAttrField;
private string valueField;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified, DataType="ID")]
public string Id {
get {
return this.idField;
}
set {
this.idField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAnyAttributeAttribute()]
public System.Xml.XmlAttribute[] AnyAttr {
get {
return this.anyAttrField;
}
set {
this.anyAttrField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string Value {
get {
return this.valueField;
}
set {
this.valueField = value;
}
}
}
}
推荐阅读
- android - 如何将所有 webview 内容转换为位图?
- python - 将输入变量分配为字典中的值时出现意外的“NameError”
- java - 根据行和列绘制一条线
- scala - 如果确切的单词序列与另一个数据帧中的一个数据帧匹配
- regex - 如何计算一个字符的出现次数,同时在谷歌表格中省略其他相同字符的出现次数?
- vue.js - Bootstrap-vue:如何使用内置的表格过滤组件过滤第二组数据?
- r - 从R中列表中的所有嵌入列表中删除一个元素
- io - Perl6:以不同用户身份运行命令
- php - 如何包含数据库中的多列或多行
- oauth - NestJS 和 PassportJS 没有刷新令牌