Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted

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>

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.