Solved

Newbie needs XML/XSD guidance

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

756 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