ਪ੍ਰੋਗਰਾਮਿੰਗ
XML DOM name ਪ੍ਰਤੀਯੋਗੀ
ਵਿਧੀ:
ਗਰਾਫਿਕ
attrObject.name
ਇੰਸਟੈਂਸ
ਸਾਰੇ ਉਦਾਹਰਨਾਂ ਵਿੱਚ, ਅਸੀਂ XML ਫਾਈਲ ਵਰਤਾਂਗੇ books.xmlਅਤੇ ਜਾਵਾਸਕ੍ਰਿਪਟ ਫੰਕਸ਼ਨ loadXMLDoc()。
ਹੇਠ ਲਿਖੇ ਕੋਡ ਸਪੈਕਸ ਕੈਟੇਗਰੀ ਪ੍ਰਤੀਯੋਗੀ ਦੇ ਨਾਮ ਅਤੇ ਮੁੱਲ ਨੂੰ ਦਿਸਾਉਂਦਾ ਹੈ:
xmlDoc=loadXMLDoc("/example/xdom/books.xml");
var x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
{
document.write(x.item(i).attributes[0].name
);
document.write(" = ");
document.write(x.item(i).attributes[0].value);
document.write("<br />");
}
ਇਸ ਕੋਡ ਦੇ ਆਉਟਪੁੱਟ:
category = children category = cooking category = web category = web