473,796 Members | 2,465 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSD help please

Hi all

I need a little help with XSD, here is my XML

<data>
<brandData>
<brandGroups>
<brandGroup>
<name>Group1</name>
</brandGroup>
<brandGroup>
<name>Group2</name>
</brandGroup>
<brandGroup>
<name>Group2</name>
</brandGroup>
</brandGroups>
<brands>
<brand>
<name>Brand1</name>
<groupName>Grou p1</groupName>
</brand>
<brand>
<name>Brand2</name>
<groupName>Grou p1</groupName>
</brand>
<brand>
<name>Brand2</name>
<groupName>Grou p1</groupName>
</brand>
</brands>
<brandData>
<data>
I need to do two things.
1) Create a key on brandGroup.name
2) Ensure that brand.groupName refers to a key on brandGroup.name

I've read lots of articles + tried many examples, but seem unable to get it
right. Would someone please help me out?

Thanks

Pete
Feb 11 '06 #1
7 1267


Peter Morris [Droopy eyes software] wrote:

I need a little help with XSD,
I need to do two things.
1) Create a key on brandGroup.name
2) Ensure that brand.groupName refers to a key on brandGroup.name


Here is an example schema

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">

<xs:element name="data">
<xs:complexType >
<xs:sequence>
<xs:element name="brandData ">
<xs:complexType >
<xs:sequence>
<xs:element name="brandGrou ps">
<xs:complexType >
<xs:sequence>
<xs:element name="brandGrou p" maxOccurs="unbo unded">
<xs:complexType >
<xs:sequence>
<xs:element name="name" type="xs:string " />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="brands">
<xs:complexType >
<xs:element name="brand" maxOccurs="unbo unded">
<xs:complexType >
<xs:sequence>
<xs:element name="name" type="xs:string " />
<xs:element name="groupName " type="xs:string " />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="brandGrou pName">
<xs:selector xpath="brandGro ups/brandGroup" />
<xs:field xpath="name" />
</xs:key>
<xs:keyref name="brandRefe rsGroup" refer="brandGro upName">
<xs:selector xpath="brands/brand" />
<xs:field xpath="groupNam e" />
</xs:keyref>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

Note that your sample XML provided (even after making it well-formed) is
not valid against that schema as you have two
<brandGroup>
<name>Group2</name>
</brandGroup>
elements which is not allowed if name is defined as a key.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Feb 11 '06 #2
Thanks very much Martin, your example clarified it for me perfectly! May I
ask a couple more questions?

I now have two more changes I need to implement. The first is a compound
key + reference.

<data>
<customerData >
<customer>
<customerSite >
<uniqueId>Custo merSite1</uniqueId>
<vendingLocatio ns>
<vendingLocatio n>
<vendingMachine s>
<vendingMachine >
<serialNumber>1 234</serialNumber>
<selections>
<selection>
<number>1</number>
</selection>
<selection>
<number>2</number>
</selection>

A site has many vending machines, each vending machine has many selections.
Later in my xml I need to reference a specific selection of a specific
vending machine

<data>
<roundData>
<visitDay>
<plannedVisit s>
<plannedVisit >
<customerSiteUn iqueId>Customer Site1</customerSiteUni queId>
<vendingMachine Visits>
<vendingMachine Visit>
<serialNumber>1 234</serialNumber>
<replenishments >
<selectionReple nishment>
<number>1</number>
</selectionReplen ishment>
<selectionReple nishment>
<number>2</number>
</selectionReplen ishment>

Could you tell me how I define a key on the vendingMachine/serialNumber +
selection/number, and also how to refer to that compound key from my
vendingMachineV isit/serialNumber +
replenishments/selectionReplen ishment/number?
Finally, this XML is going to be read on a Pocket PC so I want to keep it as
small as possible. I was considering making elements such as "name",
"serialNumb er" etc attributes instead. I tried changing this

<xs:element name="customerS ite">
<xs:complexType >
<xs:all>
<xs:element name="uniqueId" type="xs:string "/>
<xs:element name="name" type="xs:string "/>
<xs:element name="vendingLo cations">
..complex type information here
</xs:element>
</xs:all>
<xs:complexType >
</xs:element>

to this

<xs:element name="customerS ite">
<xs:complexType >
<xs:all>
<xs:attribute name="uniqueId" type="xs:string "/>
<xs:attribute name="name" type="xs:string "/>
<xs:element name="vendingLo cations">
..complex type information here
</xs:element>
</xs:all>
<xs:complexType >
</xs:element>

but XMLSpy says this is invalid. Could you tell me how to make the simple
element types into attributes and still mark them as required, whilst also
having required elements.
I really appreciate your help, it has enabled me to get some work finished
much quicker than I expected. Thank you!
Pete
Feb 12 '06 #3


Peter Morris [Droopy eyes software] wrote:

<xs:element name="customerS ite">
<xs:complexType >
<xs:all>
<xs:attribute name="uniqueId" type="xs:string "/>
<xs:attribute name="name" type="xs:string "/>
<xs:element name="vendingLo cations">
..complex type information here
</xs:element>
</xs:all>
<xs:complexType >
</xs:element>

but XMLSpy says this is invalid.


xs:all defines the contents of the element, move the attribute
definitions outside of the xs:all e.g.

<xs:element name="customerS ite">
<xs:complexType >
<xs:all>
<xs:element name="vendingLo cations">
..complex type information here
</xs:element>
</xs:all>
<xs:attribute name="uniqueId" type="xs:string "/>
<xs:attribute name="name" type="xs:string "/>
<xs:complexType >
</xs:element>
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Feb 12 '06 #4


Peter Morris [Droopy eyes software] wrote:

I now have two more changes I need to implement. The first is a compound
key + reference. Could you tell me how I define a key on the vendingMachine/serialNumber +
selection/number, and also how to refer to that compound key from my
vendingMachineV isit/serialNumber +
replenishments/selectionReplen ishment/number?


You have to use the xs:key and xs:keyref constructs as shown before so
you will have one xs:key element and one xs:keyref element and each has
one xs:selector child element, only now you need two (or more) xs:field
elements to define the several values the key respectively the key
reference consists of. Make sure that the order and type of xs:field
elements in the xs:key matches the order and type of the xs:field
elements in the xs:keyref definition.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Feb 12 '06 #5
Hi Martin

I tried having two keys, but the xpath is not obvious to me. This is
because the serialNumber is in a different path to the selection's "number".
Would you mind showing me an example?

Thanks

Pete
Feb 12 '06 #6


Peter Morris [Droopy eyes software] wrote:
I tried having two keys, but the xpath is not obvious to me. This is
because the serialNumber is in a different path to the selection's "number".
Would you mind showing me an example?


It turns out that the XPath sub language you can use with xs:field and
xs:selector is a bit restricted, it does not allow you to refer to
several fields with the same name.
If you had only one number child element then it could look alike

xs:schema id="data" xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">
<xs:element name="data">
<xs:complexType >
<xs:sequence>
<xs:element name="customerD ata">

[snipped here]

</xs:element>
<xs:element name="roundData ">

[snipped here]

</xs:sequence>
</xs:complexType>
<xs:key name="vendingMa chine">
<xs:selector
xpath="customer Data/customer/customerSite/vendingLocation s/vendingLocation/vendingMachines/vendingMachine"
/>
<xs:field xpath="serialNu mber" />
<xs:field xpath="selectio ns/selection/number" />
</xs:key>
<xs:keyref name="vendingMa chineVisits" refer="vendingM achine">
<xs:selector
xpath="roundDat a/visitDay/plannedVisits/plannedVisit/vendingMachineV isits/vendingMachineV isit"
/>
<xs:field xpath="serialNu mber" />
<xs:field xpath="replenis hments/selectionReplen ishment/number" />
</xs:keyref>
</xs:element>
</xs:schema>

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Feb 14 '06 #7
I'll have to settle for a unique ID on the number I suppose

Thanks for all your help over the last few days, I appreciate it!

Pete
Feb 14 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2171
by: Numberwhun | last post by:
Hello everyone! I am trying to learn java and have run into kind of a snag. Here is the code that I have so far: ------ <begin_code> ---------- import javax.swing.*; import javax.swing.JApplet; import javax.swing.JOptionPane; import java.awt.Graphics;
1
2011
by: HolaGoogle | last post by:
Hi all, Please help me with the following..it's realy urgent and i tried everything i could and i can't get it work properly!! Thanks in advance. Here's what i'm trying to accomplish: in my form i have a table with 3 rows (3 input text), in which user can enter values and then clik save. When he clicks the Save button, i'd like to be able to add the created items to the end of my table
0
2000
by: s_erez | last post by:
Hi, This is a realy tricky one. I have an ASP.NET application where some pages are reading data from a DB and presenting reports. In order for the user to wait while the page is reading data from the DB I am using a DIV with a please wait message which is removed once the page is loaded. In addition I am using a global error handling using the Application_Error void in the Global.asax file. when the application is loading a page which...
2
2418
by: rked | last post by:
I get nameSPAN1 is undefined when I place cursor in comments box.. <%@ LANGUAGE="VBScript" %> <% DIM ipAddress ipAddress=Request.Servervariables("REMOTE_HOST") %> <html> <head> <meta http-equiv="Content-Type" content="text/html;
7
3617
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title> </head> <style type="text/css">
4
3522
by: pshindle | last post by:
DB2 Team - I just downloaded and unzipped the new Fixpack 9 for DB2 ESE V8 for Windows (FP9_WR21350_ESE.exe). I then burned the unzipped Fixpack files to a CD. I proceded to install this Fixpack on a test machine running ESE but encountered a serious error during the install. It started 'copying new files' but then stopped cold and displayed a dialog box asking me to "Please insert disk 1". (It all fit on one CD!) I clicked OK...
23
3290
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application to create certain textboxes, labels, and combo boxes? Any ideas would be appreciated. Thanks
1
54542
PEB
by: PEB | last post by:
POSTING GUIDELINES Please follow these guidelines when posting questions Post your question in a relevant forum Do NOT PM questions to individual experts - This is not fair on them and we instruct our experts to ignore any such PMs completely Be sure to give the version of Access that you are working with and the Platform and OS if applicable.
4
2361
by: fatboySudsy | last post by:
Hi, I have constructed a client program that has given me some error codes that i just cannot see. I was wondering if a different set of eyes with much more experience than me could help me out. Here are the error codes and underneath i have listed the program. Thanks in advance for looking. client.c: In function `main': client.c:118: error: syntax error before '-' token client.c: At top level: client.c:132: error: conflicting types...
0
10456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10230
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7548
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5442
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.