PDA

View Full Version : سوال: اشکال در استفاده از schema



farhadyoosefi
چهارشنبه 25 خرداد 1390, 10: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>

mehdi.mousavi
شنبه 04 تیر 1390, 19:45 عصر
سلام.
چطوری فایل XML رو در برابر Schema ی داده شده Validate می کنید؟ در هر محیطی، عموما ابزارهایی برای اینکار وجود داره و این کار به خودی خود انجام نمیشه. بطور مثال، شما می تونید با استفاده از C# در محیط .NET، این Validation رو بدین شکل (http://support.microsoft.com/kb/307379) انجام بدید.

موفق باشید.