JavaScript in XML?

Hello,

would you explain to me why this JS test in an XML file doesn’t work?

<?xml version="1.0" ?>
<!-- <?xml-stylesheet type="text/css" href="main.css" ?> -->

<root xmlns="http://www.w3.org/1999/xhtml">

    <a:musicstore xmlns:a="http://www.w3.org/TR/html4/">
        <a:album>
            <a:name>Scenes from a Memory</a:name>
            <a:artist>Dream Theater</a:artist>
            <a:year>1999</a:year>
        </a:album>
    </a:musicstore>

    <b:musicstore xmlns:b="http://www.w3.org/TR/html4/">
        <b:album>
            <b:name>Protocosmos</b:name>
            <b:artist>Allan Holdsworth</b:artist>
            <b:year>2001</b:year>
        </b:album>
    </b:musicstore>

<script type="text/javascript">
<![CDATA[
document.getElementsbyTagName("year").innerHTML = "2000";
]]>
</script>

</root>

It is returning me this:

TypeError: undefined is not a function (evaluating 'document.getElementsbyTagName("year")')

Thank you!

See https://developer.mozilla.org/en-US/docs/Web/API/document.getElementsByTagNameNS for the call to use to get the tag in XML.

Also innerHTML will not work when you don’t have HTML.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.