向 XML 添加命名空间前缀
我有许多 POCO 类,它们生成序列化所需的 XML 结构,以作为 SOAP WS 中的返回进行传递。在选定的元素中,我需要向元素添加名称空间前缀/别名。这可能吗?如果是的话请问如何?
POCO 类
public partial class ValueTable
{
private List<ValueTableColumn> headerField;
private row[] rowField;
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("column", IsNullable = false)]
public List<ValueTableColumn> header
{
get
{
return this.headerField;
}
set
{
this.headerField = value;
}
}
/// <remarks/>
[XmlElement]
public row[] row
{
get
{
return this.rowField;
}
set
{
this.rowField = value;
}
}
}
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class row
{
private rowField[] fieldField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("field")]
public rowField[] field
{
get
{
return this.fieldField;
}
set
{
this.fieldField = value;
}
}
}
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class rowField
{
private string textField;
/// <remarks/>
public string text
{
get
{
return this.textField;
}
set
{
this.textField = value;
}
}
}
具有所需名称空间前缀/别名的示例 XML
<v21:row>
<v21:field>
<v21:text>ID-1005896</v21:text>
</v21:field>
<v21:field>
<v21:text>Smith</v21:text>
</v21:field>
<v21:field>
<v21:text>64AF6547DDSEE</v21:text>
</v21:field>
</v21:row>
目前,返回的内容不带前缀/别名。
我很感激任何帮助:)
I have a number of POCO classes that are generating the required XML structure for serializtion to be passed as return in a SOAP WS. In selected elements I need to add namespace prefix/ alais to the elements. Is this possible? If yes how please?
POCO Classes
public partial class ValueTable
{
private List<ValueTableColumn> headerField;
private row[] rowField;
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("column", IsNullable = false)]
public List<ValueTableColumn> header
{
get
{
return this.headerField;
}
set
{
this.headerField = value;
}
}
/// <remarks/>
[XmlElement]
public row[] row
{
get
{
return this.rowField;
}
set
{
this.rowField = value;
}
}
}
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class row
{
private rowField[] fieldField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("field")]
public rowField[] field
{
get
{
return this.fieldField;
}
set
{
this.fieldField = value;
}
}
}
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class rowField
{
private string textField;
/// <remarks/>
public string text
{
get
{
return this.textField;
}
set
{
this.textField = value;
}
}
}
Sample XML with required namespace prefixes/alias
<v21:row>
<v21:field>
<v21:text>ID-1005896</v21:text>
</v21:field>
<v21:field>
<v21:text>Smith</v21:text>
</v21:field>
<v21:field>
<v21:text>64AF6547DDSEE</v21:text>
</v21:field>
</v21:row>
Currently it is being returned with out the prefixes/alias.
I appreciate any help :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的东西应该有效:
something like this should work: