问题
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