在javascript中创建xml内的链接

时间:2022-07-26 01:27:36

I have an xml String as:

我有一个xml字符串:

var txt, parser, xmlDoc;
        txt = "<Employees xmlns:xlink=\"http://www.w3.org/1999/xlink\"><Employee>"
                + "<ID xlink:type=\"simple\">1</ID>"
                + "<Name>Employee1</Name>"
                + "<Description>Employee1 Description</Description>"
                + "</Employee>"
                + "<Employee>"
                + "<ID xlink:type=\"simple\">2</ID>"
                + "<Name>Employee2</Name>"
                + "<Description>Employee2 Description</Description>"
                + "</Employee></Employees>";

var htmlString = htmlEntities(txt);
        document.getElementById('empDetails').innerHTML = htmlString;
        alert("HTML formatted display: \n" + htmlString);

        function htmlEntities(str) {
            var htmlString = String(str).replace(/&/g, '&amp;').replace(/</g,
                    '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
            return htmlString;
        }

Where my empDetails is a p tag as:

我的empDetails是一个p标签:

<p id="empDetails"></p>

now i am able to show xml inside this p tag. The problem is that i want to show a hyperlink on the id's of the printed xml. So when the xml is printed in the p tag it should show a hyperlink on the id node. i tried using xlink as you can see but it's of no use.

现在我能够在这个p标签内显示xml。问题是我想在打印的xml的id上显示一个超链接。因此,当在p标签中打印xml时,它应该在id节点上显示一个超链接。我尝试使用xlink,你可以看到,但没有用。

How to achieve this. Looking forward to your answers. Thanks in advance.

如何实现这一目标。期待您的回答。提前致谢。

1 个解决方案

#1


0  

y don't you provide the xlink:href attribute in the ID tag?

你不在ID标签中提供xlink:href属性吗?

#1


0  

y don't you provide the xlink:href attribute in the ID tag?

你不在ID标签中提供xlink:href属性吗?