Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help... Can't get getElementbyId to work...

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi.. I cant get my getElementbyId() method to work...
I have an XML file with a DTD declaration at the type.. defining several attributes as type 'ID'.. In the XML I try to get the elementname into a variable so i may do as I wish later.. i've tried everything I can think of... Following is the XML + DTD, and the javascript used to import it using w3c's DOM and ms's activex object...
The only thing im concerned with now is the getElementbyId.. not any other obvious errors that you may see.. lol... P.S.. I realize the code is simple... I have the same problem on a much larger section of code.. and am was just trying somethign smaller to eliminate all other errors... Thanks.. Joss

Code:
<script>
function xmltest()
{

 var myXML, root, Name, Item, ProductNode, Title, Picture_Loc, Product_Description, Category, Cat_pic_loc, Price, Product, Ret


 myXML=new ActiveXObject(&quot;Microsoft.XMLDOM&quot;) 
 myXML.async=&quot;false&quot;
 myXML.load(&quot;test.xml&quot;)

root = myXML.documentElement
Item = myXML.getElementById(&quot;_6&quot;)

a1.innerText = Item.firstChild.text //product-->id
//a2.innerText = Item.firstChild.text //product-->productheader

}
</script>


and the XML....

Code:
<?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?>

<!DOCTYPE test [
<!ELEMENT test (product)>
  <!ELEMENT product (#PCDATA)>
  <!ATTLIST product id ID #REQUIRED>
]>
 

<test>
 <product id=&quot;_6&quot;>hi</product>
</test>
 
getElementById is not XML processing method
use:

consider:
<root>
<item id=&quot;_5&quot;>My Item</item>
<item id=&quot;_6&quot;>My Item</item>
<item id=&quot;_7&quot;>My Item</item>
</root>

root = myXML.documentElement
item = myXML.getElementsByTag(&quot;item&quot;)
for (int i=0;i<item.length;i++){
node = item;
if(node.attributes.getNamedItem(&quot;id&quot;).nodeValue==&quot;_6&quot;){
//do something
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top