1

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">

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"))

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.

Edit

ok so i got the namespaces to work with 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(order + "Order", _
                                 New XAttribute(XNamespace.Xmlns + "xsi", xsi.NamespaceName),
                                 New XAttribute(XNamespace.Xmlns + "schemaLocation", schemaLocation),
                                 New XElement("OrderHead", _
                                              New XElement("Schema", New XElement("Version", "3.05")),
                                              New XElement("Parameters", New XElement("Language", "en-GB"), New XElement("DecimalSeparator", "."), New XElement("Precision", "20.3")), _
                                              New XElement("OrderType", "Purchase Order", New XAttribute("Code", "PUO"))), _

but now in my xml i have:

<OrderHead xmlns="">
    <Schema>
      <Version>3.05</Version>
    </Schema>
    <Parameters>

is there any way of getting rid of the blank xmlns="" within the orderHead tag?

1

1 Answer 1

2

What do you get from this:

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

Dim root As New XElement(
    order + "Order", 
    New XElement(order + "Child", _
                 New XElement(order + "DifferentChild", "other content")), _
    New XElement(order + "Child2", "c2 content"), _
    New XElement(order + "Child3", "c3 content"))

Sorry, but I don't have time to test it right now.

Sign up to request clarification or add additional context in comments.

2 Comments

Look closely at my example and then look at yours.
ahhh perfect i spotted it! its the order + that i was missing on every element! thanks for your time

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.