Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 22nd, 2005, 04:41 PM
Authorized User
 
Join Date: Jul 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to yossarian Send a message via AIM to yossarian Send a message via MSN to yossarian Send a message via Yahoo to yossarian
Default Trouble nesting elements in a schema

I'm new to XML and XSD. I have an existing schema with an element, ASSET, to which I want to add a sub-element, ACCOUNT. The existing code is below:

<xs:element name="ASSET">
        <xs:complexType>
            <xs:sequence>
                <xs:complexContent>
                    <xs:restriction base="xs:anyType">
                        <xs:attribute name="BorrowerID" type="xs:IDREFS"/>
                        <xs:attribute name="_AccountIdentifier" type="xs:string"/>
                        <xs:attribute name="_CashOrMarketValueAmount" type="xs:string"/>
                        <xs:attribute name="_Type">
                            <xs:simpleType>
                                <xs:restriction base="xs:NMTOKEN">
                                    <xs:enumeration value="Automobile"/>
                                    <xs:enumeration value="CashOnHand"/>
                                    <xs:enumeration value="RelocationMoney"/>
                                    <xs:enumeration value="PendingNetSaleProceedsFromRealEstateAssets"/>
                                    <xs:enumeration value="MoneyMarketFund"/>
                                    <xs:enumeration value="TrustAccount"/>
                                    <xs:enumeration value="BridgeLoanNotDeposited"/>
                                    <xs:enumeration value="SaleOtherAssets"/>
                                    <xs:enumeration value="OtherNonLiquidAssets"/>
                                    <xs:enumeration value="Stock"/>
                                    <xs:enumeration value="GiftsNotDeposited"/>
                                    <xs:enumeration value="SecuredBorrowedFundsNotDeposited"/>
                                    <xs:enumeration value="SavingsAccount"/>
                                    <xs:enumeration value="GiftsTotal"/>
                                    <xs:enumeration value="LifeInsurance"/>
                                    <xs:enumeration value="NetWorthOfBusinessOwned"/>
                                    <xs:enumeration value="EarnestMoneyCashDepositTowardPurchase"/>
                                    <xs:enumeration value="Bond"/>
                                    <xs:enumeration value="CheckingAccount"/>
                                    <xs:enumeration value="CertificateOfDepositTimeDeposit"/>
                                    <xs:enumeration value="OtherLiquidAssets"/>
                                    <xs:enumeration value="RetirementFund"/>
                                    <xs:enumeration value="MutualFund"/>
                                    <xs:enumeration value ="Bank"/>
                                </xs:restriction>
                            </xs:simpleType>
                        </xs:attribute>
                        <xs:attribute name="_VerifiedIndicator">
                            <xs:simpleType>
                                <xs:restriction base="xs:NMTOKEN">
                                    <xs:enumeration value="Y"/>
                                    <xs:enumeration value="N"/>
                                </xs:restriction>
                            </xs:simpleType>
                        </xs:attribute>
                        <xs:attribute name="_HolderName" type="xs:string"/>
                        <xs:attribute name="_HolderStreetAddress" type="xs:string"/>
                        <xs:attribute name="_HolderCity" type="xs:string"/>
                        <xs:attribute name="_HolderState" type="xs:string"/>
                        <xs:attribute name="_HolderPostalCode" type="xs:string"/>
                        <xs:attribute name="AutomobileMakeDescription" type="xs:string"/>
                        <xs:attribute name="AutomobileModelYear" type="xs:string"/>
                        <xs:attribute name="LifeInsuranceFaceValueAmount" type="xs:string"/>
                        <xs:attribute name="OtherAssetTypeDescription" type="xs:string"/>
                        <xs:attribute name="StockBondMutualFundShareCount" type="xs:string"/>
                    </xs:restriction>
                </xs:complexContent>
                <xs:element name="Account" minOccurs="0" maxOccurs="3">
                    <xs:complexType>
                        <xs:restriction base="anyType">
                            <xs:attribute name="_Balance" type="xs:decimal"/>
                            <xs:attribute name="_AcctNumber" type="xs:string"/>
                        </xs:restriction>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

I'm getting an error when I validate the schema:

file:///c:/Documents and Settings/gbusby/My Documents/MORTGAGE_APPLICATION_v2_3.xsd:204,24: Error: complexContent content must be one of element, group, modelGroupRef. Saw {null}
file:///c:/Documents and Settings/gbusby/My Documents/MORTGAGE_APPLICATION_v2_3.xsd:261,38: Invalid child 'restriction' in the complex type

The XML document MORTGAGE_APPLICATION_v2_3.xsd is NOT valid (2 errors)


What am I doing wrong here? Any help/guidance rendered is much appreciated.

Greg
 
Old February 22nd, 2005, 05:30 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You can be excused for being confused, because the rules here seem totally devoid of reason = at any rate, I've never found any logic that enables me to remember them without looking them up. You need a good XML Schema book constantly by your side.

complexType can *either* contain complexContent/simpleContent, or it can contain the content model directly (sequence/choice/attribute etc). If you specify complexContent, then it must be immediately within the complexType, you can't have sequence in between as in your specimen.

In other words, put the xs:sequence and the xs:element inside the xs:complexContent.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Namespace trouble when nesting xslt-s dirkvdb XSLT 1 July 26th, 2007 09:02 AM
Nesting queries??? giffordpinchot Access 0 September 20th, 2006 09:58 AM
Nesting ADO recordsets yossarian Pro VB Databases 1 January 12th, 2005 06:28 PM
Trouble validating an XML document with a Schema cxs00u XML 0 March 2nd, 2004 12:22 PM
Subreports nesting svenvandevelde Crystal Reports 2 February 4th, 2004 12:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.