0

Here is the desired (required) output:

<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 ">

I've found some helpful posts to get me in the right direction. This question gets me soooo close, but there are a few issues with the solution when implemented on my side.

Here is my code:

        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);

The issues I'm having with this code:

  • The attributes are out of order; the "xmlns" attribute needs to come first
  • Every child node to my root node now has "xmlns=""" as an attribute.

I'd like to get exactly the output above.

Thanks!

Community
  • 1
  • 1

1 Answers1

0

You need to set the namespace for your elements like you did for the root. e.g. new XElement(ns + "Header")

Wouter
  • 2,540
  • 19
  • 31