www.webdeveloper.com
Results 1 to 2 of 2

Thread: make xsd schema validate this xml

  1. #1
    Join Date
    Jul 2003
    Location
    NY
    Posts
    15

    make xsd schema validate this xml

    In the following XML I want to require the USER and SEARCH_KEY nodes, but not the TRANSACTION_DATA or SEARCH_RESULT nodes. I am having trouble building an XSD schema that will do this without any side effects:



    <XYZ_TRANSACTION>

    <USER>
    <USER_ID>testuser</USER_ID>
    <PASSWORD>testpassword</PASSWORD>
    </USER>

    <TRANSACTION_DATA>
    <TRANSACTION_ID>999</TRANSACTION_ID>
    <TRANSACTION_DATE>02/23/2004</TRANSACTION_DATE>
    </TRANSACTION_DATA>

    <SEARCH_KEY>
    <ID_NUMBER>123456789</ID_NUMBER>
    </SEARCH_KEY>

    <SEARCH_RESULT>
    <STREETA>123 MAIN STREET</STREETA>
    <CITY>NEW YORK</CITY>
    <ZIP_CODE>10030</ZIP_CODE>
    </SEARCH_RESULT>

    </XYZ_TRANSACTION>

  2. #2
    Join Date
    Jan 2004
    Location
    Washington DC
    Posts
    1,107
    You can tweak this:
    Code:
    <?xml version="1.0"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                          targetNamespace="http://url_of_this_file_without_file_name"
                          xmlns="http://url_of_this_file_without_file_name">  
    	<xsd:element name="XYZ_TRANSACTION"> 
    	  <xsd:complexType>
    	    <xsd:sequence>
    	      <xsd:element ref="USER" minOccurs="1" maxOccurs="1" use="required"/>
    	      <xsd:element ref="TRANSACTION_DATA" minOccurs="1" maxOccurs="1" use="required"/>
    	      <xsd:element ref="SEARCH_KEY" minOccurs="1" maxOccurs="1" use="implied"/>
    	      <xsd:element ref="SEARCH_RESULT" minOccurs="1" maxOccurs="1" use="implied"/>
    	    </xsd:sequence>
    	  </xsd:complexType>
    	</xsd:element>
    
    	<xsd:element name="USER">
    	  <xsd:complexType>
    	    <xsd:sequence>
    	      <xsd:element ref="USER_ID" minOccurs="1" maxOccurs="1" use="required"/>
    	      <xsd:element ref="PASSWORD" minOccurs="1" maxOccurs="1" use="required"/>
    	    </xsd:sequence>
    	  </xsd:complexType>
    	</xsd:element>
    
    	<xsd:element name="TRANSACTION_DATA">
    	  <xsd:complexType>
    	    <xsd:sequence>
    	      <xsd:element ref="TRANSACTION_ID" minOccurs="1" maxOccurs="1"/>
    	      <xsd:element ref="TRANSACTION_DATE" minOccurs="1" maxOccurs="1"/>
    	    </xsd:sequence>
    	  </xsd:complexType>
    	</xsd:element>
    
    	<xsd:element name="SEARCH_KEY">
    	  <xsd:complexType>
    	      <xsd:element ref="ID_NUMBER" minOccurs="1" maxOccurs="1" use="required"/>
    	  </xsd:complexType>
    	</xsd:element>
    
    	<xsd:element name="SEARCH_RESULT">
    	  <xsd:complexType>
    	    <xsd:sequence>
    	      <xsd:element ref="STREETA" minOccurs="1" maxOccurs="1"/>
    	      <xsd:element ref="CITY" minOccurs="1" maxOccurs="1"/>
    	      <xsd:element ref="ZIP_CODE" minOccurs="1" maxOccurs="1"/>
    	    </xsd:sequence>
    	  </xsd:complexType>
    	</xsd:element>
    
    	<xsd:element name="USER_ID" type="xsd:string"/> 
    	<xsd:element name="PASSWORD" type="xsd:string"/>
    	<xsd:element name="TRANSACTION_ID" type="xsd:integer"/>
    	<xsd:element name="TRANSACTION_DATE" type="xsd:string"/>
    	<xsd:element name="ID_NUMBER" type="xsd:integer"/>
    	<xsd:element name="STREETA" type="xsd:string"/>
    	<xsd:element name="CITY" type="xsd:string"/>
    	<xsd:element name="ZIP_CODE" type="xsd:string"/>
    </xsd:schema>
    Last edited by crh3675; 03-02-2004 at 07:41 AM.
    Bittersweet web development.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles