Solved

creating xml file with namespaces

Posted on 2013-02-05
1
482 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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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. 
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now