Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/01/2005, 11:06
cvyh
 
Fecha de Ingreso: enero-2005
Mensajes: 2
Antigüedad: 19 años, 3 meses
Puntos: 0
VALIDACION XML CON Javascript

hola, quisiera que me ayuden a resover el sigueinte problema.
estoy haciendo un sistema en donde el cliente debe subir al server un documento xml, pero este docuemtno debe validarse. tengo dos opciones para esto validar del lado del server y validar del lado del cliente. Del lado del server lo he descarto pues tomaria mucho timepo( tiempo de envio y tiempo de procesamiento), por eso he optado por validar por el lado del cliente, pero esto me origina un problemilla, el problema es que nose como hacer... ya encontre como hacerlo con IE,pero falta el como hacerlos con Mozilla y talvez otros navegadores mas... Agradesco de antemano su ayuda.

Un ejemplo para validacion con IE es el siguiente:
<!---- prueba.html-->
<HTML>
<BODY onload="validate()">

<SCRIPT>
function validate()
{
xmldoc= new ActiveXObject("Microsoft.XMLDOM");
xmldoc.onreadystatechange = BienoMal;
xmldoc.validateOnParse = true;
xmldoc.load("pizzas.xml");
}

function BienoMal() {
if (xmldoc.readyState == 4)
{
var e=xmldoc.parseError;
if (xmldoc.childNodes.length == 0) {
alert(e.reason + " Line: " + e.line + " " + e.linepos);
}
else {
window.navigate("pizzas.xml");
}
}
}

</SCRIPT>

</BODY>
</HTML>

el archivo xml es este
<!-- pizzas.xml -->
<?xml version="1.0" ?>
<pizzas xmlns="x-schema:pizzas.xsd">
<pizza>
<name>The Washingtonian</name>
<toppings>
<topping>apple slices</topping>
<topping>salmon</topping>
<topping>mozzarella cheese</topping>
<topping>tomato sauce</topping>
</toppings>
<description>Who says you can't mix seafood with America's number one fruit
pie filling?</description>
<price>7.99</price>
</pizza>
<pizza>
<name>The Texan</name>
<toppings>
<topping>barbeque brisket</topping>
<topping>dill pickles</topping>
<topping>onions</topping>
<topping>mozzarella cheese</topping>
<topping>tomato sauce</topping>
</toppings>
<description>Put the lone in lone star state! Ask for extra
onions</description>
<price>7.99</price>
</pizza>
<pizza>
<name>The Mississippian</name>
<toppings>
<topping>fried catfish</topping>
<topping>greens</topping>
<topping>mozzarella cheese</topping>
<topping>tomato sauce</topping>
</toppings>
<description>This Southern treat will have you dreaming of pine
trees, Faulkner, and floating casinos.</description>
<price>7.99</price>
</pizza>
</pizzas>


el esquema el sigueinte
<!-- pizzas.xsd -->

<Schema xmlns="urn:schemas-microsoft-com:xml-data">
<ElementType name="name" content="textOnly"/>
<ElementType name="topping" content="textOnly"/>
<ElementType name="toppings" content="eltOnly" model="closed">
<element type="topping" maxOccurs="*"/>
</ElementType>
<ElementType name="description" content="textOnly"/>
<ElementType name="price" content="textOnly"/>
<ElementType name="pizza" content="eltOnly" model="closed">
<element type="name"/>
<element type="toppings"/>
<element type="description"/>
<element type="price"/>
</ElementType>
<ElementType name="pizzas" content="eltOnly" model="closed">
<element type="pizza" maxOccurs="*"/>
</ElementType>
</Schema>