xml 序列化 - 将名称空间添加到非根元素
我正在使用 C# 工作,我正在尝试进行 xml 序列化,我得到 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
和 xmlns: xsd="http://www.w3.org/2001/XMLSchema"
在根元素上,我也需要在另一个元素上。
我需要它的原因是因为我将 xml 作为字符串获取,并且我只需要在
元素上进行 xml 序列化。<?xml version="1.0" encoding="utf-8"?>
<Movie xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Header xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
....
</Header
<Title>Starship Troopers</Title>
<Rating>6.9</Rating>
<ReleaseDate>1997-11-07T00:00:00</ReleaseDate>
</Movie>
I am working in C#, I'm trying to do xml serialization I get xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
and xmlns:xsd="http://www.w3.org/2001/XMLSchema"
on the root element, I need that also on another element.
The reason that I need it, is because I get the xml as a string and I need to do xml serialization only on the <Header>
element.
<?xml version="1.0" encoding="utf-8"?>
<Movie xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Header xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
....
</Header
<Title>Starship Troopers</Title>
<Rating>6.9</Rating>
<ReleaseDate>1997-11-07T00:00:00</ReleaseDate>
</Movie>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论