Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 506
  • Last Modified:

creating xml file with namespaces

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
houlahan
Asked:
houlahan
1 Solution
 
Bob LearnedCommented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now