show xml in tree format with the help of jqGrid/treegrid

流过昼夜 提交于 2020-01-06 10:12:18

问题


I want to show an XML file with the help of jqGrid in the jsp page. The keypoint are : That Xml can be any type, means it can be parent-child level upto any level like

<?xml version="1.0" encoding="ISO-8859-1"?>

<CATALOG>
    <CD>
        <TITLE>Empire Burlesque</TITLE>
        <ARTIST>Bob Dylan</ARTIST>
        <COUNTRY>USA</COUNTRY>
        <COMPANY>Columbia</COMPANY>
        <PRICE>10.90</PRICE>
        <YEAR>1985</YEAR>
    </CD>
    <CD>
        <TITLE>Hide your heart</TITLE>
        <ARTIST>Bonnie Tyler</ARTIST>
        <COUNTRY>UK
            <STATE>
                cardif
            </STATE>
        </COUNTRY>
        <COMPANY>CBS Records</COMPANY>
        <PRICE>9.90</PRICE>
        <YEAR>1988</YEAR>
    </CD>
    <CD>
        <TITLE>Still got the blues</TITLE>
        <ARTIST>Gary Moore</ARTIST>
        <COUNTRY>UK</COUNTRY>
        <COMPANY>Virgin records
            <ALPHA>PPP
                <BETA>QQQ
                    <GAMMA>RRR</GAMMA>
                </BETA>
            </ALPHA>
        </COMPANY>
        <PRICE>10.20</PRICE>
        <YEAR>1990</YEAR>
    </CD>
</CATALOG>

-> That code shouldn't be hardcoded. -> every parent should have toggle function. means if we click on any parent their child should be hide and show.

Can Anybody help me for this


回答1:


As you need JSON for jqgrid, you can convert that xml to json with this library:

http://www.openjs.com/scripts/xml_parser/

Then, you can process it in Javascript to pass it as data parameter to jqgrid

EDIT This link can be useful for what you're trying to do:

Hope this helps. Cheers



来源:https://stackoverflow.com/questions/6578837/show-xml-in-tree-format-with-the-help-of-jqgrid-treegrid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!