问题描述
我想在jsp页面中借助jqGrid显示一个XML文件.关键点是:该Xml可以是任何类型,表示它可以是父子级别,最高可以是
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.
有人可以帮我吗
推荐答案
由于jqgrid需要JSON,因此可以使用以下库将xml转换为json:
As you need JSON for jqgrid, you can convert that xml to json with this library:
http://www.openjs.com/scripts/xml_parser/
然后,您可以使用Javascript处理它,并将其作为数据参数传递给jqgrid
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
这篇关于在jqGrid/treegrid的帮助下以树格式显示xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!