Solved

creating xml file with namespaces

Posted on 2013-02-05
1
488 Views
Last Modified: 2013-05-02
I'm trying to create a xml file:

<?xml version="1.0"?>
<Order xmlns="urn:schemas-basda-org:2000:purchaseOrder:xdr:3.01"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:schemas-basdaorg:
2000:purchaseOrder:xdr:3.01order-v3.xsd">
<OrderHead>
		<Schema>
			<Version>3.05</Version>
		</Schema>
....

Open in new window


I have the following code:

 
   Dim xsi As XNamespace = "http://www.w3.org/2001/XMLSchema-instance"
    Dim schemaLocation As XNamespace = "urn:schemas-basdaorg:2000:purchaseOrder:xdr:3.01order-v3.xsd"
Dim order As XNamespace = "urn:schemas-basda-org:2000:purchaseOrder:xdr:3.01"

    Dim root As New XElement("Root", New XAttribute("Order", order.NamespaceName), _
                             New XAttribute(XNamespace.Xmlns + "xsi", xsi.NamespaceName), _
                             New XAttribute(xsi.NamespaceName + "schemaLocation", schemaLocation.NamespaceName), _
                             New XElement("Child", _
                                          New XElement("DifferentChild", "other content")), _
                             New XElement("Child2", "c2 content"), _
                             New XElement("Child3", "c3 content"))

Open in new window

however when i run the code i get the following error:

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

Open in new window

Thanks Houlahan
0
Comment
Question by:houlahan
1 Comment
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 38860185
0x3a is the colon character.  I don't get to use URN namespace very much with LINQ-to-XML, so this is a great question to research...

You might try to add braces:

Dim order As XNamespace = "{urn:schemas-basda-org:2000:purchaseOrder:xdr:3.01}"
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question