Including xmlns in my XML file

可紊 提交于 2019-12-23 23:34:47

问题


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

回答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" />


来源:https://stackoverflow.com/questions/21577318/including-xmlns-in-my-xml-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!