0

I want create an xml document with the namepace attributes along the lines of this:

<MyXmlDoC xmlns="http://abc" xmlns:brk="http://123">

Using the System.Xml.Linq xml library, iv done this:

     public static XAttribute XmlNamepace()
        {
            return new XAttribute(XName.Get("xmlns"), "http://abc");
        }

        public static XAttribute brkNamepace()
        {
            return new XAttribute(XNamespace.Xmlns + "brk", "http://123");
        }

 var rootNode = new XElement("MyXmlDoC",XmlNamepace(),brkNamepace());

But this produces this error:

The prefix '' cannot be redefined from '' to 'http://abc' within the same start element tag

What am I doing wrong

1 Answer 1

1

(From your answer) you need to add the ChildNode with the rt namespace, this should work:

rootNode.Add(new XElement(rt + "ChildNode", "Hello"));
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks that did the trick, you deserve an accepted answer, but this techically doesnt answer my orginal question
I think it's the same issue, you're not setting the namespace correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.