473,791 Members | 3,071 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSD to Class to XML file results in elements with xmlns="" tag

3 New Member
Hi all,

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
  1. xsd source.xsd /c /l:vb
Contents of the source.xsd file:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-16"?>
  2. <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">
  3.     <xsd:element name="root">
  4.         <xsd:complexType>
  5.             <xsd:sequence>
  6.                 <xsd:element minOccurs="0" maxOccurs="unbounded" name="partner-dto">
  7.                     <xsd:annotation>
  8.                         <xsd:documentation>This is the information about partners (customers - suppliers).</xsd:documentation>
  9.                     </xsd:annotation>
  10.                     <xsd:complexType>
  11.                         <xsd:all>
  12.                             <xsd:element minOccurs="0" maxOccurs="1" name="internal-reference" type="xsd:string">
  13.                                 <xsd:annotation>
  14.                                     <xsd:documentation>DB Primary key in Deal-IT.</xsd:documentation>
  15.                                 </xsd:annotation>
  16.                             </xsd:element>
  17.                             <xsd:element minOccurs="1" maxOccurs="1" name="external-reference" type="xsd:string">
  18.                                 <xsd:annotation>
  19.                                     <xsd:documentation>DB Primary key in external ERP system.</xsd:documentation>
  20.                                 </xsd:annotation>
  21.                             </xsd:element>
  22.                             <xsd:element minOccurs="1" maxOccurs="1" name="functional-reference" type="xsd:string">
  23.                                 <xsd:annotation>
  24.                                     <xsd:documentation>Functional key.</xsd:documentation>
  25.                                 </xsd:annotation>
  26.                             </xsd:element>
  27.                             <xsd:element minOccurs="1" maxOccurs="1" name="description" type="xsd:string">
  28.                                 <xsd:annotation>
  29.                                     <xsd:documentation>Extra information.</xsd:documentation>
  30.                                 </xsd:annotation>
  31.                             </xsd:element>
  32.                             <xsd:element minOccurs="1" maxOccurs="1" name="allow-partial-deliveries" type="xsd:boolean">
  33.                                 <xsd:annotation>
  34.                                     <xsd:documentation>Flag that indicates that partial deliveries for this partner are allowed.</xsd:documentation>
  35.                                 </xsd:annotation>
  36.                             </xsd:element>
  37.                             <xsd:element minOccurs="0" maxOccurs="1" name="main-address-reference" type="xsd:string">
  38.                                 <xsd:annotation>
  39.                                     <xsd:documentation>The id of the main address. The addresses are defined via the address-dto</xsd:documentation>
  40.                                 </xsd:annotation>
  41.                             </xsd:element>
  42.                             <xsd:element minOccurs="1" maxOccurs="1" name="state-reference" type="xsd:string">
  43.                                 <xsd:annotation>
  44.                                     <xsd:documentation>external-reference to the partner status.</xsd:documentation>
  45.                                 </xsd:annotation>
  46.                             </xsd:element>
  47.                         </xsd:all>
  48.                         <xsd:attribute name="message-status" use="required">
  49.                             <xsd:annotation>
  50.                                 <xsd:documentation>Indicates the transaction type: I=Insert U=Update D=Delete.</xsd:documentation>
  51.                             </xsd:annotation>
  52.                             <xsd:simpleType>
  53.                                 <xsd:restriction base="xsd:token">
  54.                                     <xsd:length value="1" />
  55.                                     <xsd:enumeration value="I" />
  56.                                     <xsd:enumeration value="U" />
  57.                                     <xsd:enumeration value="D" />
  58.                                 </xsd:restriction>
  59.                             </xsd:simpleType>
  60.                         </xsd:attribute>
  61.                     </xsd:complexType>
  62.                 </xsd:element>
  63.             </xsd:sequence>
  64.         </xsd:complexType>
  65.     </xsd:element>
  66. </xsd:schema>
Next I fill the generated classes through code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim _root As New root
  3.  
  4.         Dim _partner As New rootPartnerdto
  5.         With _partner
  6.             .internalreference = ""
  7.             .externalreference = "1564"
  8.             .functionalreference = "1564 Naamklant"
  9.             .description = "Naamklant"
  10.             .allowpartialdeliveries = True
  11.             .mainaddressreference = ""
  12.             .statereference = ""
  13.             .messagestatus = rootPartnerdtoMessagestatus.I
  14.         End With
  15.  
  16.  
  17.         Dim _partner2 As New rootPartnerdto
  18.         With _partner2
  19.             .internalreference = ""
  20.             .externalreference = "1564"
  21.             .functionalreference = "1564 Naamklant"
  22.             .description = "Naamklant"
  23.             .allowpartialdeliveries = True
  24.             .mainaddressreference = ""
  25.             .statereference = ""
  26.             .messagestatus = rootPartnerdtoMessagestatus.I
  27.         End With
  28.         'lst.Add(_partner2)
  29.  
  30.         _root.partnerdto = New rootPartnerdto() {_partner, _partner2}
  31.  
  32.         Dim _output As String = PCNObjecten.XMLExport.Export(_root)
  33.  
The export function works like this:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. Public Shared Function Export(ByVal _root As root) As String
  4.  
  5.         Dim _output As String
  6.  
  7.         Dim writer As New XmlSerializer(GetType(root)) 
  8.         Dim _str As New MemoryStream
  9.         writer.Serialize(_str, _root)
  10.         _str.Flush()
  11.         _str.Seek(0, SeekOrigin.Begin)
  12.         Dim _rdr As New StreamReader(_str)
  13.         _output = _rdr.ReadToEnd()
  14.  
  15.         Debug.WriteLine(_output)
  16.         Return _output
  17.  
  18.     End Function
  19.  
The output xml:

Expand|Select|Wrap|Line Numbers
  1. <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.company.net/product">
  2.   <partner-dto message-status="I" xmlns="">
  3.     <internal-reference />
  4.     <external-reference>1564</external-reference>
  5.     <functional-reference>1564 Naamklant</functional-reference>
  6.     <description>Naamklant</description>
  7.     <allow-partial-deliveries>true</allow-partial-deliveries>
  8.     <main-address-reference />
  9.     <state-reference />
  10.   </partner-dto>
  11.   <partner-dto message-status="I" xmlns="">
  12.     <internal-reference />
  13.     <external-reference>1564</external-reference>
  14.     <functional-reference>1564 Naamklant</functional-reference>
  15.     <description>Naamklant</description>
  16.     <allow-partial-deliveries>true</allow-partial-deliveries>
  17.     <main-address-reference />
  18.     <state-reference />
  19.   </partner-dto>
  20. </root>
  21.  
Now the question part:
- 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
Aug 29 '07 #1
4 4821
jkmyoung
2,057 Recognized Expert Top Contributor
In your schema, you've got elementFormDefa ult="unqualifie d" which will put the elements you declare in there in the default xmlns="" namespace.

Seems the problem is telling the program that you want those elements to be in the same namespace when you generate the schema with the xsd command.
Aug 29 '07 #2
BorisBoshond
3 New Member
Thanks for your answer,

So as long if the xsd sais elementFormDefa ult=Unqualified , the output will always contain the empty xmlns="" tag?

Is that xmlns="" tag valid? Or will our xml cause validationerror s?

I ran some tests with different elementFormDefa ult and attributeFormDe fault settings, here are the results:

with attributeFormDe fault = UnQualified
and elementFormDefa ult = UnQualified:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.company.net/product">
  3.   <partner-dto message-status="I" xmlns="">
  4.     <internal-reference />
  5.     <external-reference>1564</external-reference>
  6.     <functional-reference>1564 Naamklant</functional-reference>
  7.     <description>Naamklant</description>
  8.     <allow-partial-deliveries>true</allow-partial-deliveries>
  9.     <main-address-reference />
  10.     <state-reference />
  11.   </partner-dto>
  12.   <partner-dto message-status="I" xmlns="">
  13.     <internal-reference />
  14.     <external-reference>1564</external-reference>
  15.     <functional-reference>1564 Naamklant</functional-reference>
  16.     <description>Naamklant</description>
  17.     <allow-partial-deliveries>true</allow-partial-deliveries>
  18.     <main-address-reference />
  19.     <state-reference />
  20.   </partner-dto>
  21.   <sales-order-dto message-status="I" xmlns="">
  22.     <delivery-address-reference xsi:nil="true" />
  23.     <ship-together>true</ship-together>
  24.     <sales-reference />
  25.     <order-date>0001-01-01T00:00:00</order-date>
  26.   </sales-order-dto>
  27. </root>
with attributeFormDe fault = Qualified
and elementFormDefa ult = UnQualified:

Expand|Select|Wrap|Line Numbers
  1. <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.company.net/product">
  2.   <partner-dto d2p1:message-status="I" xmlns:d2p1="http://www.company.net/product" xmlns="">
  3.     <internal-reference />
  4.     <external-reference>1564</external-reference>
  5.     <functional-reference>1564 Naamklant</functional-reference>
  6.     <description>Naamklant</description>
  7.     <allow-partial-deliveries>true</allow-partial-deliveries>
  8.     <main-address-reference />
  9.     <state-reference />
  10.   </partner-dto>
  11.   <partner-dto d2p1:message-status="I" xmlns:d2p1="http://www.company.net/product" xmlns="">
  12.     <internal-reference />
  13.     <external-reference>1564</external-reference>
  14.     <functional-reference>1564 Naamklant</functional-reference>
  15.     <description>Naamklant</description>
  16.     <allow-partial-deliveries>true</allow-partial-deliveries>
  17.     <main-address-reference />
  18.     <state-reference />
  19.   </partner-dto>
  20.   <sales-order-dto d2p1:message-status="I" xmlns:d2p1="http://www.company.net/product" xmlns="">
  21.     <delivery-address-reference xsi:nil="true" />
  22.     <ship-together>true</ship-together>
  23.     <sales-reference />
  24.     <order-date>0001-01-01T00:00:00</order-date>
  25.   </sales-order-dto>
  26. </root>
With attributeFormDe fault = Qualified
and elementFormDefa ult = Qualified:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.company.net/product">
  3.   <partner-dto d2p1:message-status="I" xmlns:d2p1="http://www.company.net/product">
  4.     <d2p1:internal-reference />
  5.     <d2p1:external-reference>1564</d2p1:external-reference>
  6.     <d2p1:functional-reference>1564 Naamklant</d2p1:functional-reference>
  7.     <d2p1:description>Naamklant</d2p1:description>
  8.     <d2p1:allow-partial-deliveries>true</d2p1:allow-partial-deliveries>
  9.     <d2p1:main-address-reference />
  10.     <d2p1:state-reference />
  11.   </partner-dto>
  12.   <partner-dto d2p1:message-status="I" xmlns:d2p1="http://www.company.net/product">
  13.     <d2p1:internal-reference />
  14.     <d2p1:external-reference>1564</d2p1:external-reference>
  15.     <d2p1:functional-reference>1564 Naamklant</d2p1:functional-reference>
  16.     <d2p1:description>Naamklant</d2p1:description>
  17.     <d2p1:allow-partial-deliveries>true</d2p1:allow-partial-deliveries>
  18.     <d2p1:main-address-reference />
  19.     <d2p1:state-reference />
  20.   </partner-dto>
  21.   <sales-order-dto d2p1:message-status="I" xmlns:d2p1="http://www.company.net/product">
  22.     <d2p1:delivery-address-reference xsi:nil="true" />
  23.     <d2p1:ship-together>true</d2p1:ship-together>
  24.     <d2p1:sales-reference />
  25.     <d2p1:order-date>0001-01-01T00:00:00</d2p1:order-date>
  26.   </sales-order-dto>
  27. </root>
That last result seems like the best solution, namespace wise, no discussion.

But I think the first version is more "readable" (no qualifiers), only problem is that xmlns="" tag. If that's invalid xml then I wonder the use of setting elementFormDefa ult=UnQualified in the first place.

I'll post any progress in this topic.

Regards,

Boris
Aug 30 '07 #3
BorisBoshond
3 New Member
Hmmm, the other company sais that XSD is valid and it's our job to fill in the xmlns tag correctly...

So if anyone has a suggestion on how to do this or explain me why this can't be done, I'd be very impressed.

The only 'hack' I can think of is removing the xmlns="" tag through String.Replace from the output.

Regards,

Boris
Sep 4 '07 #4
jkmyoung
2,057 Recognized Expert Top Contributor
If the XSD is valid, then output xml you have originally is valid.

Part of your xml just happens to be in the default namespace. This is still valid xml.
Sep 5 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
10043
by: Mike Dickens | last post by:
hi, i'm sure this has come up before but havn't managed to find an answer. if i have the following xslt <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet method="xml" version="1.0" xmlns:ns1="abc" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes" media-type="text/xml" standalone="yes" version="1.0"/> <xsl:template match="/">
3
7144
by: Keith Hill | last post by:
I am creating an XmlDocument in code and then using XmlTextWriter via doc.WriteTo(xwriter) to output the result to a text box. I have a root element that defines a default namespace. However, the sub-elements are created without any namespaces like so: XmlElement elem = doc.CreateElement("Foo"); root.AppendChild(elem); but in the output I get this:
9
5449
by: Anubhav Jain | last post by:
Hi, I am having few .net source files(.cs or .vb) and I want to dynamically generate the corresponding .net project file(.csproj or .vbproj) for them without using visual studio.So that I could be able to generate and compile the project on the enviroments where Visual Studio.Net is not installed. Thanks and Regards, Anubhav Jain MTS Persistent Systems Pvt. Ltd. Ph:+91 712 2226900(Off) Extn: 2431 Mob : 094231 07471
3
5466
by: olympus_mons | last post by:
Hi all, my XML looks like: <root xmlns="tempuri.org"> <result xmlns=""> <date>2006-09-14</date> <status>ok</status> </result> </root>
0
4178
by: Peter Nofelt | last post by:
Hi all, ISSUE: ==================== In SQL 2005 (sp2) I get the following error when preforming a bulk insert with an associated xml format file: "Could not bulk insert. Unknown version of format file" Question:
3
2880
by: Lee | last post by:
Hello guys, I am new to XML and working on a XSLT to transforn yahoo shopping search result to html. my problem is the return XML contain xmlns in root element, here is the sample xml: <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="aproductsearch.xslt"?> <ProductSearch xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:aprods" xsi:schemaLocation="urn:yahoo:aprods...
7
20871
by: Tim Slattery | last post by:
I'm trying to handle the onChange event in an <input type="file"> element. In IE, there's no problem: the event fires when a file in the "open" box is doubleclicked, or the "Open" button in the box is clicked, or "Enter" is hit in the attached text box. I can get the value of the element. But in Netscape 7, onChange doesn't fire until focus leaves the element. When you double-click a file name or click "open" in the Open box, the...
1
8200
by: niharnayak2003 | last post by:
Hi All, I am facing the problem in Typecast inside the Generic class. I need a function which will take two param 1:-Xpath 2:- XMLDOC and return me what i will need. here is the code for accessing to the Generic class. private double mtrxgraphdata; private XMLdocument Matrixdata;
36
5119
by: Roedy Green | last post by:
The only browser I have encountered that supports <colgroup><col class="behold"></colgroup> to apply a CSS style to a whole column, is Microsoft Internet Explorer. I have been told it SHOULD NOT do so, since this is not part of the specification. How then to you apply styles to entire columns? Surely you don't have to write <td class="behold"on every row item.
0
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10427
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10155
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.