xml - No declaration found for element -
i have simple xml , xsd files. using xerces generate .h/cpp files when run application gives error:
no declaration found element 'x:books'
my xml file is:
<?xml version="1.0"?> <x:books xmlns:x="urn:books" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="urn:bookstore books.xsd"> <book id="bk001"> <author>writer</author> <title>the first book</title> <genre>fiction</genre> <price>44.95</price> <pub_date>2000-10-01</pub_date> <review>an amazing story of nothing.</review> </book> <book id="bk002"> <author>poet</author> <title>the poet's first poem</title> <genre>poem</genre> <price>24.95</price> <pub_date>2001-10-01</pub_date> <review>least poetic poems.</review> </book> </x:books>
and xsd file is:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/xmlschema" targetnamespace="urn:bookstore" xmlns:bks="urn:bookstore"> <xsd:element name="books" type="bks:booksform"/> <xsd:complextype name="booksform"> <xsd:sequence> <xsd:element name="book" type="bks:bookform" minoccurs="0" maxoccurs="unbounded"/> </xsd:sequence> </xsd:complextype> <xsd:complextype name="bookform"> <xsd:sequence> <xsd:element name="author" type="xsd:string"/> <xsd:element name="title" type="xsd:string"/> <xsd:element name="genre" type="xsd:string"/> <xsd:element name="price" type="xsd:float" /> <xsd:element name="pub_date" type="xsd:date" /> <xsd:element name="review" type="xsd:string"/> </xsd:sequence> <xsd:attribute name="id" type="xsd:string"/> </xsd:complextype> </xsd:schema>
i have done simpler demo xerces 1 uses namespaces , think seems causing trouble.
change namespace on root element of xml file (urn:books
) match targetnamespace
(urn:bookstore
) of xsd...
change
<x:books xmlns:x="urn:books" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="urn:bookstore books.xsd">
to
<x:books xmlns:x="urn:bookstore" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="urn:bookstore books.xsd">
and xml validate against xsd.
Comments
Post a Comment