I'm trying to add this XML element:

<cp:prop name="given_name" value="UK" />

It has to be formatted exactly as above.

I've tried this but it formats differently:

Dim cp = XNamespace.Get("cp")
Dim newElement As New XElement(cp + "prop", New XAttribute("name", "given_name"), New XAttribute("value", givenName)))

It formats like this:

<prop name="given_name" value="UK" xmlns="cp" />

Please help!! :)

Recommended Answers

All 3 Replies

Do this instead:

Dim newElement As New XElement("cp:prop", New XAttribute("name", "given_name"), New XAttribute("value", givenName)))

Tried that, you get this error:

'The ':' character, hexadecimal value 0x3A, cannot be included in a name.'

This damn XML stuff is going to kill me :)

I found this excerpt on MSDN.

Dim aw As XNamespace = "http://www.adventure-works.com"
Dim root As XElement = New XElement(aw + "Root", _
New XAttribute(XNamespace.Xmlns + "aw", "http://www.adventure-works.com"), _
New XElement(aw + "Child", "Child content"))

Which produces this output:

<aw:Root xmlns:aw="http://www.adventure-works.com">
   <aw:Child>Child content</aw:Child>
</aw:Root>

http://msdn.microsoft.com/en-us/library/bb387075.aspx

I hope it helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.