借助 jqGrid/treegrid 以树格式显示 xml
我想在 jsp 页面中借助 jqGrid 显示 XML 文件。关键点是: Xml 可以是任何类型,意味着它可以是父子级别到任何级别,例如
<?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>
->该代码不应该被硬编码。 ->每个家长都应该有切换功能。意味着如果我们点击任何父母,他们的孩子应该隐藏和显示。
有人可以帮我吗
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 jqgrid 需要 JSON,因此可以使用此库将该 xml 转换为 json:
http://www.jqgrid.json。 openjs.com/scripts/xml_parser/
然后,您可以在 Javascript 中处理它,将其作为数据参数传递给 jqgrid
编辑 此链接可以对您想做的事情有用:
希望这会有所帮助。干杯
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