XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 27th, 2006, 12:08 PM
superprogrammer superprogrammer is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Posts: 794 superprogrammer User rank is Lance Corporal (50 - 100 Reputation Level)superprogrammer User rank is Lance Corporal (50 - 100 Reputation Level)superprogrammer User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 6 Days 17 h 27 m 57 sec
Reputation Power: 7
Send a message via AIM to superprogrammer Send a message via MSN to superprogrammer Send a message via Yahoo to superprogrammer
Conditions in XSD

I have an XML with following tags

<root tag>
<A>xxx </A>
<B>xxx </B>
<C>xxx </C>
<D>xxx </D>
<E>xxx </E>
</root tag>

I want to mention in my XSD, the following things:

1) If tag <A>is present, then <B> is optional and the tags <C>, <D>, <E> should not be present.

2) If tag <C>is present, then <D> is optional and the tags <A>, <B> should not be present.
How to do it?
__________________
Contact info:
Primary email: advanced.programmer@gmail.com
MSN/email: superprg@hotmail.com
AIM: superprg

Reply With Quote
  #2  
Old July 28th, 2006, 02:20 AM
sandeep.rohilla's Avatar
sandeep.rohilla sandeep.rohilla is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Location: New Delhi, India
Posts: 138 sandeep.rohilla User rank is Lance Corporal (50 - 100 Reputation Level)sandeep.rohilla User rank is Lance Corporal (50 - 100 Reputation Level)sandeep.rohilla User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 4 Days 13 h 59 m 52 sec
Reputation Power: 4
Thumbs up

hi superprogrammer,

hope it helps.

Code:

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

    <xs:element name="root">
        <xs:complexType>
            <xs:choice>                                
                    <xs:group ref="t1"/>
                <xs:group ref="t2"/>
            </xs:choice>
        </xs:complexType>
    </xs:element>
    
    <xs:group name="t1">
        <xs:sequence>
            <xs:element name="a"/>
            <xs:element name="b" minOccurs="0"/>
        </xs:sequence>
    </xs:group>
    
    <xs:group name="t2">
        <xs:sequence>
            <xs:element name="c"/>
            <xs:element name="d" minOccurs="0"/>
            <xs:element name="e" />
        </xs:sequence>
    </xs:group>    
    
</xs:schema>


cheers,

Sandeep

Intrasphere

Reply With Quote
  #3  
Old July 28th, 2006, 02:39 PM
jkmyoung jkmyoung is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 576 jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 3 h 58 m 24 sec
Reputation Power: 55
regular expressions
ab? | cd?e? | b?d?e?

are you allowed to have elements bde, or no elements at all, or b and e, but not d?

Reply With Quote
  #4  
Old July 29th, 2006, 12:58 AM
sandeep.rohilla's Avatar
sandeep.rohilla sandeep.rohilla is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Location: New Delhi, India
Posts: 138 sandeep.rohilla User rank is Lance Corporal (50 - 100 Reputation Level)sandeep.rohilla User rank is Lance Corporal (50 - 100 Reputation Level)sandeep.rohilla User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 4 Days 13 h 59 m 52 sec
Reputation Power: 4
Thumbs up

hi superprogrammer,

schema provided above would only allow

Code:
<root_tag>
<A>xxx </A>
<B>xxx </B> (optional)
</root_tag>


or

Code:
<root_tag>
<C>xxx </C>
<D>xxx </D> (optional)
<E>xxx </E>
</root_tag>


I hope this is what you wanted ?

cheers mate,

sandeep

Reply With Quote
  #5  
Old January 29th, 2009, 04:52 AM
sikorka sikorka is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 1 sikorka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 25 sec
Reputation Power: 0
question about conditions

Hi

My question is a bit similar to superprg question.

My xml looks as follows:
<mySth>
<a></a>
<b></b>
<c_is_optional></c_is_optional>
</mySth>

<otherSth>
<a></a>
<b></b>
</otherSth>

How can I do make my xsd guarantee that <c_is_optional> can only occur in element with prefix 'my'? It cannot occur in element starting with 'other'.

Anna

Reply With Quote
  #6  
Old February 17th, 2009, 06:47 PM
newtechie newtechie is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2009
Posts: 2 newtechie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 10 sec
Reputation Power: 0
About Conditions

Hi,

I am new XSD's.
Could anyone guide how to draw an XSD with the following conditions.

My requirement i slike this.

<root>
<a/>
<b/>
<c/>
<d/>
<e/>
</root>

Here If <c> is present then only <d> should be present otherwize <d> should not.

How to make this possible.

Help would be appreciated.

Thanks.

Reply With Quote
  #7  
Old February 18th, 2009, 10:43 AM
jkmyoung jkmyoung is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 576 jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 3 h 58 m 24 sec
Reputation Power: 55
-> sikorka.
Make multiple types. done.

->newtechie

Have a nested sequence. eg. something like: (pseudo)
Code:
<sequence>
  <a>
  <b>
  <sequence minoccurs=0>
    <c>
    <d>
  </sequence>
  <e>
</sequence>

add minoccurs=0 to the other elements (a b e) as necessary
Assuming you mean the "if and only if" case.

Reply With Quote
  #8  
Old February 18th, 2009, 11:28 AM
newtechie newtechie is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2009
Posts: 2 newtechie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 10 sec
Reputation Power: 0
Conditions in XSD

Yep, got it....
Thank you very much.

Quote:
Originally Posted by jkmyoung
-> sikorka.
Make multiple types. done.

->newtechie

Have a nested sequence. eg. something like: (pseudo)
Code:
<sequence>
  <a>
  <b>
  <sequence minoccurs=0>
    <c>
    <d>
  </sequence>
  <e>
</sequence>

add minoccurs=0 to the other elements (a b e) as necessary
Assuming you mean the "if and only if" case.

Reply With Quote
  #9  
Old May 29th, 2009, 09:10 AM
arm4n arm4n is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 1 arm4n User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 27 sec
Reputation Power: 0
Hi, I have a similiar but different problem. The condition doesn't refers to an element, but a value of an element, is it possible ?
If element 'A' has value other than '1', then element B has to appear:
<Data>
<A>2</A>
<B>yes</B>
</Data>

But if Element 'A' has the value '1', then Element 'B' must not appear:
<Data>
<A>1</A>
</Data>

Thank you in advanced !

Reply With Quote
  #10  
Old July 1st, 2009, 09:55 AM
play4fun play4fun is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Posts: 1 play4fun User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 53 sec
Reputation Power: 0
hi all
I have two question:
1. For schema bellow :

Code:
<xsd:schema>
...
<xsd:element name="root" nillable="false">
<xsd:complexType>
    <xsd:all>

      <xsd:element maxOccurs="1" minOccurs="1" name="el1" type="xsd:int"/>
      <xsd:element maxOccurs="1" minOccurs="1" name="el2" type="xsd:int"/>
 
    </xsd:all>

    <xsd:attribute name="m" use="required">
        <xsd:simpleType>
            <xsd:restriction base="xsd:string">
                <xsd:enumeration value="r"/>
                <xsd:enumeration value="ra"/>
            </xsd:restriction>
        </xsd:simpleType>
    </xsd:attribute>
</xsd:complexType>
</xsd:element>
</xsd:schema>


How will have to be modified that :
- if mode ( attribute m ) value is r , element el2 to be mandatory( minOccurs to be 1 )
- if mode ( attribute m ) value is ra, element el2 to be optional ( minOccurs to be 0 )

2.Second question : I have this element

Code:
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Description" nillable="true">
        <xsd:complexType>
          <xsd:simpleContent>
            <xsd:extension base="xsd:string">
              <xsd:attribute name="Sequence" type="types:ValidInt_1_4" use="required"/>
              <xsd:attribute name="Use" type="enum:ArticleDescriptionTypeEnumeration" use="required"/>
            </xsd:extension>
          </xsd:simpleContent>
        </xsd:complexType>
      </xsd:element>


where validInt1_4 is a integer from 1 to 4, and ArticleDescriptionTypeEnumeration is a enumeration with 2 values, TYPE1 and TYPE2
Until now all were fine; but now i have to put one condition more, i can have only maxim 2 descriptions of type TYPE1 and max 2 descriptions of type TYPE2.
How cand be done this ?

Thanks all and best regards,
Marian

Reply With Quote
  #11  
Old July 7th, 2009, 11:20 AM
jkmyoung jkmyoung is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 576 jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 3 h 58 m 24 sec
Reputation Power: 55
arm4n, play4fun q1: no. Cooccurence constraint. You'd need another validation method besides xml schema.

q2, can you instead limit Description with maxoccurs = 4?

Reply With Quote
  #12  
Old July 28th, 2009, 08:05 PM
bharath1880 bharath1880 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Posts: 1 bharath1880 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 38 sec
Reputation Power: 0
XSD constraints / validations

Hi techies,

I hv one question to share.. on xsd's
here is the prob desc

I have a element "Name" which has enum values say "kumar" and "Miller"
and i had another element "Address" with enum values "Inida" and "US"

Now when I create xml file and pass Name = Kumar and Address= "US", when Validates it shld throw me err. and when I pass Name=Kumar and Address = India it shld validate the xml file. Now question is how can I achieve this..?

Please post ur suggestions.

Regards
Bharat

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Conditions in XSD


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek