Hope someone is able and willing to help me with following problem.
I received a xsd file from another company, our company i supposed to return xml based on that xsd.
Problem is that I don't really understand how these namespace work in xml.
(I am however aware of what problems namespaces solve)
I'm not even sure if the provided xsd is 'common' practice, although it validates correctly.
So I'll describe exactly what I've been doing:
I've converted the .xsd file (i posted contents below) to VB classes with the VS.NET 2005 xsd command:
Expand|Select|Wrap|Line Numbers
- xsd source.xsd /c /l:vb
Expand|Select|Wrap|Line Numbers
- <?xml version="1.0" encoding="utf-16"?>
- <xsd:schema xmlns="http://www.company.net/product" xmlns:tellit="http://www.company.net/product" targetNamespace="http://www.company.net/product" version="7.6" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" attributeFormDefault="unqualified">
- <xsd:element name="root">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element minOccurs="0" maxOccurs="unbounded" name="partner-dto">
- <xsd:annotation>
- <xsd:documentation>This is the information about partners (customers - suppliers).</xsd:documentation>
- </xsd:annotation>
- <xsd:complexType>
- <xsd:all>
- <xsd:element minOccurs="0" maxOccurs="1" name="internal-reference" type="xsd:string">
- <xsd:annotation>
- <xsd:documentation>DB Primary key in Deal-IT.</xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <xsd:element minOccurs="1" maxOccurs="1" name="external-reference" type="xsd:string">
- <xsd:annotation>
- <xsd:documentation>DB Primary key in external ERP system.</xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <xsd:element minOccurs="1" maxOccurs="1" name="functional-reference" type="xsd:string">
- <xsd:annotation>
- <xsd:documentation>Functional key.</xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <xsd:element minOccurs="1" maxOccurs="1" name="description" type="xsd:string">
- <xsd:annotation>
- <xsd:documentation>Extra information.</xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <xsd:element minOccurs="1" maxOccurs="1" name="allow-partial-deliveries" type="xsd:boolean">
- <xsd:annotation>
- <xsd:documentation>Flag that indicates that partial deliveries for this partner are allowed.</xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <xsd:element minOccurs="0" maxOccurs="1" name="main-address-reference" type="xsd:string">
- <xsd:annotation>
- <xsd:documentation>The id of the main address. The addresses are defined via the address-dto</xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <xsd:element minOccurs="1" maxOccurs="1" name="state-reference" type="xsd:string">
- <xsd:annotation>
- <xsd:documentation>external-reference to the partner status.</xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- </xsd:all>
- <xsd:attribute name="message-status" use="required">
- <xsd:annotation>
- <xsd:documentation>Indicates the transaction type: I=Insert U=Update D=Delete.</xsd:documentation>
- </xsd:annotation>
- <xsd:simpleType>
- <xsd:restriction base="xsd:token">
- <xsd:length value="1" />
- <xsd:enumeration value="I" />
- <xsd:enumeration value="U" />
- <xsd:enumeration value="D" />
- </xsd:restriction>
- </xsd:simpleType>
- </xsd:attribute>
- </xsd:complexType>
- </xsd:element>
- </xsd:sequence>
- </xsd:complexType>
- </xsd:element>
- </xsd:schema>
Expand|Select|Wrap|Line Numbers
- Dim _root As New root
- Dim _partner As New rootPartnerdto
- With _partner
- .internalreference = ""
- .externalreference = "1564"
- .functionalreference = "1564 Naamklant"
- .description = "Naamklant"
- .allowpartialdeliveries = True
- .mainaddressreference = ""
- .statereference = ""
- .messagestatus = rootPartnerdtoMessagestatus.I
- End With
- Dim _partner2 As New rootPartnerdto
- With _partner2
- .internalreference = ""
- .externalreference = "1564"
- .functionalreference = "1564 Naamklant"
- .description = "Naamklant"
- .allowpartialdeliveries = True
- .mainaddressreference = ""
- .statereference = ""
- .messagestatus = rootPartnerdtoMessagestatus.I
- End With
- 'lst.Add(_partner2)
- _root.partnerdto = New rootPartnerdto() {_partner, _partner2}
- Dim _output As String = PCNObjecten.XMLExport.Export(_root)
Expand|Select|Wrap|Line Numbers
- Public Shared Function Export(ByVal _root As root) As String
- Dim _output As String
- Dim writer As New XmlSerializer(GetType(root))
- Dim _str As New MemoryStream
- writer.Serialize(_str, _root)
- _str.Flush()
- _str.Seek(0, SeekOrigin.Begin)
- Dim _rdr As New StreamReader(_str)
- _output = _rdr.ReadToEnd()
- Debug.WriteLine(_output)
- Return _output
- End Function
Expand|Select|Wrap|Line Numbers
- <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.company.net/product">
- <partner-dto message-status="I" xmlns="">
- <internal-reference />
- <external-reference>1564</external-reference>
- <functional-reference>1564 Naamklant</functional-reference>
- <description>Naamklant</description>
- <allow-partial-deliveries>true</allow-partial-deliveries>
- <main-address-reference />
- <state-reference />
- </partner-dto>
- <partner-dto message-status="I" xmlns="">
- <internal-reference />
- <external-reference>1564</external-reference>
- <functional-reference>1564 Naamklant</functional-reference>
- <description>Naamklant</description>
- <allow-partial-deliveries>true</allow-partial-deliveries>
- <main-address-reference />
- <state-reference />
- </partner-dto>
- </root>
- Why is that xmlns attribute empty? I think it should not be present, since the default namespace should be "http://www.company.net/product"?
- What am I doing wrong, or is there something wrong with the .xsd definition?
Can I fix this without changing the .xsd definition?
Thanks if you took the time to read or even run this code.
Regards,
Boris