Solved

Newbie needs XML/XSD guidance

Posted on 2011-09-12
5
436 Views
Last Modified: 2012-05-12
I'm new to XML.
Below is an XSD from a webservice I've been tasked to Read and Store in our database.
Question: Do I need to allow for multiple CustomerOrderUnit's?
Meaning, given the below XSD, do I need to code/parse for this to ever happen?

<xs:element name="CustomerOrderRequest">
       <xs:element name="CustomerOrder">
           <xs:element name="CustomerOrderUnit">
            </xs:element>
           <xs:element name="CustomerOrderUnit">
           </xs:element>
           <xs:element name="CustomerOrderUnit">
           </xs:element>
       </xs:element>
</xs:element>

or ... will the web service only return ...
     one CustomerOrderRequest
     containing one CustomerOrder
     containing one CustomerOrderUnit

=============================================== BEGIN XSD
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003"
xmlns="http://IndividualCustomerOrderRequest"
targetNamespace="http://IndividualCustomerOrderRequest"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="CustomerOrderRequest">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="MessageId" type="xs:string" />
        <xs:element name="DateCreated" type="xs:dateTime" />
        <xs:element name="CreatedBy" type="xs:string" />
        <xs:element name="StatusChangeAuthor" type="xs:string" />
        <xs:element name="MessageTypeId" type="xs:string" />
        <xs:element name="CustomerOrder">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="CustomerOrderId" type="xs:integer" />
              <xs:element name="PromotionalMaterialType" type="xs:string" />
              <xs:element minOccurs="0" name="AffiliateId" type="xs:long" />
              <xs:element name="AffiliateOrderNumber" type="xs:string" />
              <xs:element name="CustomerOrderUnit">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="CustomerOrderUnitId" type="xs:integer" />
                    <xs:element name="Name" type="xs:string" />
                    <xs:element name="Company" type="xs:string" />
                    <xs:element name="Address1" type="xs:string" />
                    <xs:element name="Address2" type="xs:string" />
                    <xs:element name="City" type="xs:string" />
                    <xs:element name="State" type="xs:string" />
                    <xs:element name="Zip" type="xs:string" />
                    <xs:element name="Country" type="xs:string" />
                    <xs:element name="PhoneNumber" type="xs:string" />
                    <xs:element name="EmailAddress" type="xs:string" />
                    <xs:element name="ShipTogether" type="xs:string" />
                    <xs:element name="ItemId" type="xs:integer" />
                    <xs:element name="Sku" type="xs:string" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
=============================================== END XSD

Thanks

Volking

0
Comment
Question by:volking
  • 2
  • 2
5 Comments
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 36527326
do I need to code/parse for this to ever happen

Yes. you should have some custom code written to parse the file. the coding will depend upon the technology you use.
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 36527553
Hi Volking,

In this schema,
A "CustomerOrderRequest"
has exactly one "CustomerOrder"
that has exactly one "CustomerOrderUnit" with exactly one "CustomerOrderUnitId"

In this schema there are no maxOccurs indicating that there could be more than one of each
So your code (and database scheme) will be same to take that into account

But, you need of course to know how the schema can evolve.
I can very much imagine that in future a customerOrderUnit could be multiple in a customerOrder
(so it might be safer to take that into account already)

In short... there is always one occurence of a child in the current schema,
up to you to estimate the risk of future evolutions of the schema

@shasunder, not answering teh question as I understand it
0
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 36527705
Gertone, you are right. I overlooked the question.  Based on the provided schema, it is referring to only one customerorder. It would be good if the schema is altered to handle many customer orders to avoid future alterations.
0
 
LVL 5

Author Comment

by:volking
ID: 36529162
@Gertone - Thanks

You mention maxOccurs ... I do have maxOccurs in another XSD ... see below ... so with this one, I could have ZERO to "N" ... right?

=============================================== BEGIN XSD
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://TradersLibrary.BizTalk.Orchestrations.InventoryAdjustmentLogProcess" targetNamespace="http://TradersLibrary.BizTalk.Orchestrations.InventoryAdjustmentLogProcess" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="InventoryAdjustmentLog">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" name="Adjustment">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="AdjustmentID" type="xs:int" />
              <xs:element name="ISBN" type="xs:string" />
              <xs:element name="Quantity" type="xs:int" />
              <xs:element name="ReasonCode" type="xs:int" />
              <xs:element name="Comment" type="xs:string" />
              <xs:element name="WarehouseKey" type="xs:int" />
              <xs:element name="DateAdjusted" type="xs:dateTime" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
=============================================== END XSD
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 36529171
welcome,

yes, in InventoryAdjustmentLog you will have 0 or more "Adjustment" elements
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
DOM question 5 78
surrogate key in database world 6 83
Excel VBA and XML - traversing the nodes 2 68
Create html table using xsl 8 28
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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. 
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 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

15 Experts available now in Live!

Get 1:1 Help Now