• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using namspaces with x:parse/x:out

 
Helmut Lerch
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hy all,

I have an xml-file with a namespace declaration. For example:

--file.xml--
<?xml version="1.0"?>
<sn:root xmlns:sn="somenamespace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="somenamespace somenamespace.xsd">
<sn:item>Some Text</sn:item>
</sn:root>

How can I parse and access the content of this file with jsp? The following code produces only an output if I omit the xmlns declaration in "file.xml".

--file.jsp---
<c:import url="file.xml" var="xml"/>
<x :parse xml="${xml}" var="doc" />
<x ut select="$doc/root/item" />

Thanks very much for helping,
Helmut
[ November 07, 2004: Message edited by: Helmut Lerch ]
 
Helmut Lerch
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After some serching I found the answer on my on:

<c:import url="file.xml" var="xml"/>
<x:parse xml="${xml}" var="doc" />
<xut select="$doc/*[local-name()='root' and namespace-uri()='somenamespace']/*[local-name()='item' and namespace-uri()='somenamespace']" />

Helmut
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic