Solved

Newbie needs XML/XSD guidance

Posted on 2011-09-12
5
446 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
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. 
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

752 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