Parsing XML file using Java JSTL library; x:out does not display node-specific data
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</Em开发者_运维百科ail>
<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?
You are probably experiencing namespace problems. Try a document without a namespace and see if this works.
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>
精彩评论