PDA

Visualizza la versione completa : [Java] Parsing XML


bermar
19-01-2005, 16:07
ho questo file XML:

<?xml version="1.0" ?>
<product-catalog>
<product sku="123456" name="The Product">
<description locale="en_US">An excellent product.</description>
<description locale="es_MX">Un producto excellente.</description>
<price locale="en_US" unit="USD">99.95</price>
<price locale="es_MX" unit="MXP">9999.95</price>
</product>
</product-catalog>

e da validare con questo file XSD:

<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element type="product-catalog"/>
<xsd:complexType name="productCatalog">
<xsd:element type="productType"
minOccurs="1"/>
</xsd:complexType>
<xsd:complexType name="productType">
<xsd:element name="description"
type="xsd:string" minOccurs="1">
<xsd:attribute name="locale"
type="xsd:string"/>
</xsd:element>
<xsd:element name="price"
type="xsd:decimal" minOccurs="1">
<xsd:attribute name="locale"
type="xsd:string"/>
<xsd:attribute name="unit"
type="xsd:string"/>
</xsd:element>
<xsd:attribute name="sku"
type="xsd:decimal"/>
<xsd:attribute name="name"
type="xsd:string"/>
</xsd:complexType>
</xsd:schema>

Al momento del parsing del file XML, la mia Servlet java mi restituisce il seguente errore:

Element type "product-catalog" is not declared in the dtd or schema.
org.xml.sax.SAXParseException: Element type "product-catalog" is not declared in the dtd or schema.
at weblogic.apache.xerces.framework.XMLParser.reportE rror(XMLParser.java:1109)
at weblogic.apache.xerces.validators.common.XMLValida tor.reportRecoverableXMLError(XMLValidator.java:1
731)
at weblogic.apache.xerces.validators.common.XMLValida tor.validateElementAndAttributes(XMLValidator.jav
a:3322)
at weblogic.apache.xerces.validators.common.XMLValida tor.callStartElement(XMLValidator.java:1148)
at weblogic.apache.xerces.framework.XMLDocumentScanne r$ContentDispatcher.dispatch(XMLDocumentScanner.j
ava:1033)
at weblogic.apache.xerces.framework.XMLDocumentScanne r.parseSome(XMLDocumentScanner.java:399)
at weblogic.apache.xerces.framework.XMLParser.parse(X MLParser.java:994)
at weblogic.xml.jaxp.WebLogicXMLReader.parse(WebLogic XMLReader.java:123)
at weblogic.xml.jaxp.RegistryXMLReader.parse(Registry XMLReader.java:125)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:3 46)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:2 32)
at it.siemens.simulator.servlet.ValidationTest.parseS AXSchema(ValidationTest.java:130)
at it.siemens.simulator.servlet.ValidationTest.doPost (ValidationTest.java:63)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:853)
at weblogic.servlet.internal.ServletStubImpl.invokeSe rvlet(ServletStubImpl.java:262)
at weblogic.servlet.internal.ServletStubImpl.invokeSe rvlet(ServletStubImpl.java:198)
at weblogic.servlet.internal.WebAppServletContext.inv okeServlet(WebAppServletContext.java:2678)
at weblogic.servlet.internal.ServletRequestImpl.execu te(ServletRequestImpl.java:2412)
at weblogic.kernel.ExecuteThread.execute(ExecuteThrea d.java:140)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.ja va:121)



Qualcuno mi sa indicare dov' il problema?
grazie! :dh:

MMarzia
19-01-2005, 17:42
il linguaggio va specificato anche nel titolo



ps: la prossima volta per rendere pi leggibile il codice includilo nel tag [*code]..[*/code] (senza asterisco)

Loading