我有这段代码,由于某种原因,它没有写出名称或命名空间或属性
public class MultiSpeakHeader : MessageHeader
{
protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
{
writer.WriteAttributeString("AppName", "A");
writer.WriteAttributeString("AppVersion", "1");
writer.WriteAttributeString("CSUnits", "feet");
}
public override string Name
{
get { return "MultiSpeakMsgHeader"; }
}
public override string Namespace
{
get { return "http://www.multispeak.org/Version_3.0"; }
}
}
该类实例的结果如下:
<MultiSpeakHeader xmlns="http://schemas.datacontract.org/2004/07/my.app" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/>
我需要这个:
<MultiSpeakMsgHeader xmlns="http://www.multispeak.org/Version_3.0" AppName="A" AppVersion="1" CSUnits="feet" />
代码使用:
AddressHeader[] header = { AddressHeader.CreateAddressHeader(new MultiSpeakHeader()) };
答案 0 :(得分:0)
我可以添加属性,但根节点需要有前缀。我试图避免它但不成功。
writer.WriteXmlnsAttribute("test", this.Namespace);
writer.WriteAttributeString("AppName", "A");
writer.WriteAttributeString("AppVersion", "1");
writer.WriteAttributeString("CSUnits", "feet");