Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

java - cvc-elt.1.a: Cannot find the declaration of element 'Stock'. [2]

Currently using Netbeans 8.2 for my XML and XSD and I keep getting this error

cvc-elt.1.a: Cannot find the declaration of element 'Stock'. [2]

THIS IS MY XML

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Stock xmlns="http://xml.netbeans.org/schema/books">
    <stockcollection>
        <Stock_name>Microsoft</Stock_name>
        <sign>MSFT</sign>
        <shares>40</shares>
        <how_much>300</how_much>
            <StockDescription>
                <date>16/06/2020</date>   
                <currency>USD</currency>
                <share_price>60</share_price>
             </StockDescription>  
    </stockcollection>
    <stockcollection>
        <Stock_name>Disney</Stock_name>
        <sign>DIS</sign>
        <share>50</share>
        <how_much>140</how_much>
            <StockDescription>
                <date>03/06/2020</date>
                <currency>USD</currency>
                <share_price>300</share_price>
            </StockDescription>
    </stockcollection>
    <stockcollection>
        <Stock_name>Alibaba</Stock_name>
        <sign>BABA</sign>
        <shares>40</shares>
        <how_much>100</how_much>
            <StockDescription>
                <date>19/09/2020</date>
                <money>USD</money>
                <share_price>160</share_price>
            </StockDescription>    
    </stockcollection>
</Stock>


This is my XSD

<?xml version="1.0"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://xml.netbeans.org/schema/books"
            xmlns:tns="http://xml.netbeans.org/schema/books"
            elementFormDefault="qualified">
    
    <xsd:complexType name="Stock">
        <xsd:sequence>
            <xsd:element name="Stock_name" type="xsd:string"/>
            <xsd:element name="symbol" type="xsd:string"/>
            <xsd:element name="shares" type="xsd:int"/>
            <xsd:element name ="how_much" type="xsd:int"/>
            <xsd:element name="StockDescription"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name = "StockDescription">
        <xsd:sequence>
            <xsd:element name="date" type="xsd:date"/>
            <xsd:element name="money" type="xsd:string"/>
            <xsd:element name="share_price" type="xsd:double"/>
        </xsd:sequence>
    </xsd:complexType>
   
    <xsd:element name="available">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="stock_collection" type="tns:Stock" minOccurs="0" maxOccurs="unbounded"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

</xsd:schema>

What should I do to change for me to get rid of the error that's being presented? At first I thought it was my netbeans(I've had some issues with the setup at first), but I checked with a online validation and it came with the same error.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to declare a global element with name 'Stock'. Currently, you only have a complex type with that name.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...