AJBM Posted May 18, 2013 at 01:58 PM Report #507915 Posted May 18, 2013 at 01:58 PM Boas! Eu tenho este ficheiro xml. <?xml version="1.0" encoding="UTF-8"?> <store-invoice xmlns:store="http://www.store.com" number="1" year="2011"> Some Invoice text <client nipc="123456789"> Cristóvão Sousa <address xmlLang="pt"> <street>Rua da Avenida Nº 71</street> LocalX, ConcelhoY <postal-Code number="4444-444" place="Porto"/> Portugal </address> </client> <line number="1"> <product iva-tax="23">DVD-RAM</product> <quantity n="5"/> <price currency="euros">15</price> </line> <line number="2"> <chip-product xmlns:chip="http://www.chip.com" iva-tax="23"> RAM 2Gb <chip-code>MEM-RAM-0x00123</chip-code> </chip-product> <quantity n="10"/> <price currency="dollar">330</price> </line> </store-invoice> E tenho que fazer um ficheiro xsd, para validar o xml <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="store-invoice"> <xs:complexType> <xs:sequence> <xs:element name="client"> <xs:complexType> <xs:sequence> <xs:element name="address"> <xs:complexType> <xs:sequence> <xs:element name="street"/> <xs:element name="postal-Code"> <xs:complexType> <xs:attribute name="number" type="xs:string"/> <xs:attribute name="place" type="xs:string"/> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="xmlLang"/> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="nipc"/> </xs:complexType> </xs:element> <xs:element name="line" maxOccurs="unbounded" minOccurs="1"> <xs:complexType> <xs:sequence> <xs:element name="quantity"> <xs:complexType> <xs:attribute name="n" type="xs:integer"/> </xs:complexType> </xs:element> <xs:element name="price"> <xs:complexType> <xs:attribute name="currency" type="xs:string"/> </xs:complexType> </xs:element> <xs:choice> <xs:sequence> <xs:element name="product" maxOccurs="1" minOccurs="0"> <xs:complexType> <xs:attribute name="iva-tax"/> </xs:complexType> </xs:element> <xs:element name="chip-product" maxOccurs="1" minOccurs="0"> <xs:complexType> <xs:sequence> <xs:element name="chip-code"/> </xs:sequence> <xs:attribute name="xmlns-chip" type="xs:string"/> <xs:attribute name="iva-tax" type="xs:integer"/> </xs:complexType> </xs:element> </xs:sequence> </xs:choice> </xs:sequence> <xs:attribute name="number" type="xs:short"/> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="number" type="xs:integer"/> <xs:attribute name="year" type="xs:gYear"/> </xs:complexType> </xs:element> </xs:schema> Ao validar tenho alguns erros um dos quais é cvc-complex-type.2.3: Element 'address' cannot have character [children], because the type's content type is element-only.
nelsonr Posted May 18, 2013 at 02:28 PM Report #507919 Posted May 18, 2013 at 02:28 PM Boas, assim por alto... o melhor é teres um elemento para o nome do cliente, bem como para o resto do conteúdo que está à "solta" (ex: LocalX, ConcelhoY,) No elemento Line, está definido que vem o Quantity, Price e depois o Product ou chip-product, mas no XML tens no Line 1 o product primeiro.
AJBM Posted May 18, 2013 at 02:55 PM Author Report #507925 Posted May 18, 2013 at 02:55 PM O ficheiro xml foi me dado assim penso que não posso alterar o ficheiro xml, ou seja, o conteúdo que esta a solta deve ter que estar a solta.
AJBM Posted May 19, 2013 at 01:28 PM Author Report #507974 Posted May 19, 2013 at 01:28 PM Ja consegui resolver quase todos os erros, so me falta resolver um cvc-complex-type.3.2.2: Attribute 'store:noNamespaceSchemaLocation' is not allowed to appear in element 'store-invoice'. <store-invoice xmlns:store="http://www.store.com" store:noNamespaceSchemaLocation="ex2Ficha5.xsd" number="145" year="2011" > Some Invoice text <client nipc="123456789"> Cristóvão Sousa <address xmlLang="pt"><street>Rua da Avenida Nº 71</street> LocalX, ConcelhoY <postal-Code number="4444-444" place="Porto"/>Portugal</address> </client> <line number="1"> <quantity n="5"/> <price currency="euros">15</price> <product iva-tax="23">DVD-RAM</product> </line> <line number="2"> <quantity n="10"/> <price currency="dollar">330</price> <chip-product xmlns:chip="http://www.chip.com" iva-tax="23"> RAM 2Gb <chip-code>MEM-RAM-0x00123</chip-code> </chip-product> </line> </store-invoice>
AJBM Posted May 19, 2013 at 03:08 PM Author Report #507982 Posted May 19, 2013 at 03:08 PM já consegui coloquei isto xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" e já funcionou
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now