2

How can I add the two lines below in my xDocument?

I am creating an xml file with Xelements and Xattributes. Can you tell my how can I include this in my xml file please?

<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03">

I am getting xmlns="" on the next tag for some reason. A sample is shown below.

<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03">

<FirstTag xmlns="">
pnuts
  • 58,317
  • 11
  • 87
  • 139
user3274252
  • 57
  • 1
  • 6

1 Answers1

1
XNamespace ns = "urn:iso:std:iso:20022:tech:xsd:pain.001.001.03";
var doc = new XElement(ns + "Document",
              new XAttribute(XNamespace.Xmlns + "xsi", 
                             "http://www.w3.org/2001/XMLSchema-instance"));

Result:

<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03" />
Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459