1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
<html>
<head>
<title> XML dans Microsoft Navigateurs </title>
<script language="javascript" type="text/javascript">
var xmlDoc;
function loadxml()
{
xmlDoc = new ActiveXObject ( "Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.onreadystatechange = readXML;
xmlDoc.load ( "employee.xml");
alert ( "Root nom de la balise XML:");
}
function ReadXML()
{
if (xmlDoc.readyState == 4)
{
/ / Utilisation documentElement Propriétés
/ / Output entreprise
alert ( "Root nom de la balise XML:" + xmlDoc.documentElement.tagName);
/ / Utilisation firstChild Propriétés
/ / Output année
alert ( "Premier Enfant:" + xmlDoc.documentElement.childNodes [1]. firstChild.tagName);
/ / Utilisation lastChild Propriétés
/ / Output moyenne
alert ( "Last Child:" + xmlDoc.documentElement.childNodes [1]. lastChild.tagName);
/ / Utilisation de propriétés et des attributs nodeValue
/ / Ici, à la fois la déclaration sera de retour le même résultat
/ / Output 001
alert ( "Valeur Node:" + xmlDoc.documentElement.childNodes [0]. attributs [0]. nodeValue);
alert ( "Valeur Node:" + xmlDoc.documentElement.childNodes [0]. attributes.getNamedItem ( "id"). nodeValue);
/ / Utilisation getElementByTagName Propriétés
/ / Ici, à la fois la déclaration sera de retour le même résultat
/ / Output 2000
alert ( "getElementsByTagName:" + xmlDoc.getElementsByTagName ( "year") [0]. attributes.getNamedItem ( "id"). nodeValue);
/ / Utilisation de texte Propriétés
/ / Output John
alert ( "Text Content for Employee Tag:" + xmlDoc.documentElement.childNodes [0]. texte);
/ / Utilisation hasChildNodes Propriétés
/ / Output True
alert ( "Vérification de noeuds enfants:" + xmlDoc.documentElement.childNodes [0]. hasChildNodes);
}
}
</script>
</head>
<body Onload="loadxml();">
<input type="button" name="ok" value="Ok" onclick="ReadXML()"/>
</body>
</html> |
Partager