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
Solved

Newbie needs XML/XSD guidance

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

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…
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…

809 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