以下是所需的输出:
<BatchAttestationRequest xmlns="http://cms.gov/nlr/attestation/batch/request/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://cms.gov/nlr/attestation/batch/request/1.0 BatchAttestationRequest.xsd ">
我找到了一些有用的帖子让我朝着正确的方向前进。This question让我非常接近,但是当在我身上实现时,解决方案会出现一些问题。
这是我的代码:
XNamespace ns = @"http://cms.gov/nlr/attestation/batch/request/1.0";
XNamespace xsi = @"http://www.w3.org/2001/XMLSchema-instance";
XElement xml_file = new XElement(ns + "BatchAttestationRequest",
new XAttribute(XNamespace.Xmlns + "xsi", xsi.NamespaceName),
new XAttribute(xsi + "schemaLocation", @"http://cms.gov/nlr/attestation/batch/request/1.0 BatchAttestationRequest.xsd "),
header, // child nodes
attestations,
trailer);我在这个代码中遇到的问题是:
我想得到上面的输出。
谢谢!
发布于 2015-02-13 20:13:51
您需要为元素设置名称空间,就像为根设置名称空间一样。例如新的XElement(ns + "Header")
https://stackoverflow.com/questions/28504548
复制相似问题