Parsing XML file using Java JSTL library; x:out does not display node-specific data

旧城冷巷雨未停 提交于 2019-12-24 12:09:07

问题


Here is my xml file:

<User xmlns="http://schemas.datacontract.org/2004/07/IntranetEFCodeFirst.Objects" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<CostCentre i:nil="true"/>
<DeskNo i:nil="true"/>
<Domain>MyDomain</Domain>
<Email>marco@beirut.co.uk</Email>
<Extension>2354</Extension>
<FirstName>Marco</FirstName>
<KnownAs>Marco l'ancien</KnownAs>
</User>

If I do this:

<c:import url="http://mydomain.co.uk/myFile.xml" var="xmlDoc"/>
<x:parse xml="${xmlDoc}" var="output"/>
<x:out select="$output" />

It returns:

MyDomainmarco@beirut.co.uk2354MarcowankerMarco l'ancien

I want to display a node-specific content using

<c:import url="http://mydomain.co.uk/myFile.xml" var="xmlDoc"/>
<x:parse xml="${xmlDoc}" var="output"/>
<x:out select="$output/User/FirstName" />
<x:out select="$output/User/Email" />

But it returns nothing.

Any idea what's going wrong?


回答1:


You are probably experiencing namespace problems. Try a document without a namespace and see if this works.




回答2:


Thanks Michael'O, the issue did come from the XML document itself.

I changed the XML doc to the following and it worked fine

<?xml version="1.0" encoding="ISO-8859-1"?>
<User>
    <Domain>MyDomain</Domain>
    <Email>marco@beirut.co.uk</Email>
    <Extension>2354</Extension>
    <FirstName>Marco</FirstName>
    <KnownAs>Marco l'ancien</KnownAs>
</User>


来源:https://stackoverflow.com/questions/7027091/parsing-xml-file-using-java-jstl-library-xout-does-not-display-node-specific-d

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