Cioa a tutti, seguendo l' esempio del mio libro ho prodotto un file XML con il suo file schema XDR e la pagina aspx per convalidare il mio XML. Seguendo questa via, il libro dice che la pagina aspx non dovrebbe dare nessuna segnalazione di errore ma invece la da ed e questa
Elemento 'Attribute' non supportato in questo contesto.
Line: 2 Position: 12
Elemento 'Attribute' non supportato in questo contesto.
Line: 2 Position: 12
Elemento 'elemnte' non supportato in questo contesto.
Line: 2 Position: 12
Nessuna convalida eseguita.
Line: 35 Position: 13
Ed io non so che fare
il file XML è questo
Codice PHP:
<?xml version="1.0"?>
<bookstore xmlns="x-schema:books-schema.xdr">
<book genre="novel" style="hardcover">
<title>The Handmaid' s Tale</title>
<price>19.95</price>
<author>
<first-name>Margaret</first-name>
<last-name>Atwood</last-name>
</author>
</book>
<book genre="novel" style="hardcover">
<title>The Poisonwood Bible</title>
<price>11.99</price>
<author>
<first-name>Barbara</first-name>
<last-name>Kingsolver</last-name>
</author>
</book>
<book genre="novel" style="hardcover">
<title>Hannibal</title>
<price>27.95</price>
<author>
<first-name>Richard</first-name>
<last-name>Harris</last-name>
</author>
</book>
<book genre="novel" style="hardcover">
<title>Focault' s Pendulum</title>
<price>22.95</price>
<author>
<first-name>Umberto</first-name>
<last-name>Eco</last-name>
</author>
</book>
</bookstore>
il file schema XDR è questo
Codice PHP:
<?xml version="1.0"?>
<Schema xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes">
<ElementType name="first-name" content="textOnly" />
<ElementType name="last-name" content="textOnly" />
<ElementType name="name" content="textOnly" />
<ElementType name="price" content="textOnly"
dt:type="fixed.14.4" />
<ElementType name="author" content="eltOnly" order="one">
<group order="seq">
<element type="name" />
</group>
<group order="seq">
<element type="first-name" />
<element type="last-name" />
</group>
</ElementType>
<ElementType name="title" content="textOnly" />
<AttributeType name="genre" dt:type="string" />
<AttributeType name="style" dt:type="enumeration"
dt:values="paperback hardcover" />
<ElementType name="book" content="eltOnly">
<Attribute type="genre" required="yes" />
<Attribute type="style" required="yes" />
<element type="title" />
<element type="author" />
<elemnte type="price" />
</ElementType>
<ElementType name="bookstore" content="eltOnly">
<element type="book" />
</ElementType>
</Schema>
e la pagina aspx è questa
Codice PHP:
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Schema" %>
<script runat="server">
private reader as XMLTextReader
private validator as XMLValidatingReader
sub Page_Load(obj as object, e as eventargs)
try
reader = new XmlTextReader(Server.MapPath _
("books2.xml"))
validator = new XMLValidatingReader(reader)
validator.ValidationType = ValidationType.XDR
AddHandler Validator.ValidationEventHandler, new _
ValidationEventHandler(addressof showError)
while validator.Read()
end while
catch ex as Exception
response.write("Error accessing XML file")
finally
reader.Close
end try
end sub
sub ShowError(obj as object, e as ValidationEventArgs)
response.write("<font color=""red"">" & e.Message & _
"
")
if (reader.LineNumber > 0)
Response.write("Line: " & reader.LineNumber & _
" Position: " & reader.LinePosition & _
"</font>
</p>")
end if
end sub
</script>
<html><body>
</body></html>
Grazie per l' aiuto