farhadyoosefi
چهارشنبه 25 خرداد 1390, 11:29 صبح
سلام دوستان
من جند وقته که دارم مستندات سایت w3school رو درباره xml می خونم ولی کمی مشکل دارم ممنون می شم اگه دوستان حرفه ای تر من رو راهنمایی کنن من یه فایل xml ساده به نام bookstore.xml دارم و یه schema به نام BookStore.xsd تا valid یا notvalid بودن مقادیر فایل bookstore.xml رو چک کنه
اما فایل bookstore.xml اصلا BookStore.xsd رو نمی فهمه ,مثلا من یه attribute به نام price دارم که type اون تو فایل schemaم از نوع integer هست و انتظار دارم که وقتی به اون یه مقدار string میدم browser بهم خطا بده ملی این طور نیست
<?xml version="1.0"?>
<bookstore xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="BookStore.xsd">
<book price="sdfad" publicationdate="1987-05-11" ISBN="1-861003-11-0">
<title>java</title>
<author>
<first-name>alex</first-name>
<last-name>Shuni</last-name>
</author>
<genre>learning</genre>
</book>
</bookstore>
<?xml version="1.0" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xsd:element name="bookstore" type="bookstoreType" />
<xsd:complexType name="bookstoreType">
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:element name="book" type="bookType" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="bookType">
<xsd:sequence>
<xsd:element name="title" type="xsd:string" />
<xsd:element name="author" type="authorName" />
<xsd:element name="genre" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="price" type="xsd:integer" use="required" />
<xsd:attribute name="publicationdate" type="xsd:date" />
<xsd:attribute name="ISBN" type="xsd:string" />
</xsd:complexType>
<xsd:complexType name="authorName">
<xsd:sequence>
<xsd:element name="first-name" type="xsd:string" />
<xsd:element name="last-name" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
من جند وقته که دارم مستندات سایت w3school رو درباره xml می خونم ولی کمی مشکل دارم ممنون می شم اگه دوستان حرفه ای تر من رو راهنمایی کنن من یه فایل xml ساده به نام bookstore.xml دارم و یه schema به نام BookStore.xsd تا valid یا notvalid بودن مقادیر فایل bookstore.xml رو چک کنه
اما فایل bookstore.xml اصلا BookStore.xsd رو نمی فهمه ,مثلا من یه attribute به نام price دارم که type اون تو فایل schemaم از نوع integer هست و انتظار دارم که وقتی به اون یه مقدار string میدم browser بهم خطا بده ملی این طور نیست
<?xml version="1.0"?>
<bookstore xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="BookStore.xsd">
<book price="sdfad" publicationdate="1987-05-11" ISBN="1-861003-11-0">
<title>java</title>
<author>
<first-name>alex</first-name>
<last-name>Shuni</last-name>
</author>
<genre>learning</genre>
</book>
</bookstore>
<?xml version="1.0" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xsd:element name="bookstore" type="bookstoreType" />
<xsd:complexType name="bookstoreType">
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:element name="book" type="bookType" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="bookType">
<xsd:sequence>
<xsd:element name="title" type="xsd:string" />
<xsd:element name="author" type="authorName" />
<xsd:element name="genre" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="price" type="xsd:integer" use="required" />
<xsd:attribute name="publicationdate" type="xsd:date" />
<xsd:attribute name="ISBN" type="xsd:string" />
</xsd:complexType>
<xsd:complexType name="authorName">
<xsd:sequence>
<xsd:element name="first-name" type="xsd:string" />
<xsd:element name="last-name" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>