Solved

Newbie needs XML/XSD guidance

Posted on 2011-09-12
5
428 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

705 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

21 Experts available now in Live!

Get 1:1 Help Now