Solved

creating xml file with namespaces

Posted on 2013-02-05
1
491 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

756 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