2012-07-16 3 views
1

내 XML에서이 줄을 어떻게 만드나요? 간단한 네임 스페이스를 어떻게 추가합니까?

(가) 나는이이었다 온 닫습니다 (문제는 네임 스페이스) :

XDocument doc = new XDocument(); 
XElement root = new XElement("root", 
    new XAttribute("name", Name), 
    new XAttribute(XNamespace.Xmlns, Namespace)//<-- XNamespace.Xmlns is not good 
); 

나는 또한 새로운 XAttribute ("의 xmlns"네임 스페이스)와 tryed,하지만 난 그냥 그것을 얻을하지 않습니다.

답변

1

찾았습니다. 그것은 위대한 작품.

XDocument doc = new XDocument(); 
XElement root = new XElement("root", 
    new XAttribute("name", Name) 
    ); 
doc.Add(root); 
XNamespace xmlns = Namespace; 
doc.Root.Name = xmlns + root.Name.LocalName; 
관련 문제