2 Replies Latest reply on Oct 30, 2009 9:34 AM by Natalie D

    Parsing XML inside JSF

    Natalie D Newbie

      Hello, could anybody tell me how to parse XML file inside a JSF page?


      The thing's that I've got XML file and want to put some data from it into my JSF page. My first thought was to include JSTL Core and XML libs and to do something like this:




      <c:import var="some-info-doc" src="some-info.xml" /> 
      <x:parse  var="some-info-xml" xml="some-info-doc" />
      
      <h:outputText>                                  
         <x:out select="$some-info-xml/a-piece-of-data" />            
      </h:outputText>





      However, this code resulted in error. c:import was not recognized. So, I decided to play with a local piece of XML:



      <x:parse var="simple">
         <child>basic</child>
      </x:parse>
      
      <h:outputText>                                  
         <x:out select="$simple/child" />             
      </h:outputText>





      This led to the child tag being printed in the result page. And the output came from the x:parse tag, not h:output.


      So that, is there any alternative to parse XML inside a JSF page (not including XML being sent as an object from a certain by-me-written module)? Or are there any errors in my code?

        • 1. Re: Parsing XML inside JSF
          Leo van den berg Master

          Hi,


          If I understand it correctly you want to include a piece of XML code in your page. If you want to do that as-is, you can use the RichFaces insert tag and do some pretty printing. If you want to dot the parsing, you have to write a bean which does the parsing and get the output to a value which you can include (if its text) in the h:outputText and if its XML you could use the Richfaces insert


          Leo




          P.S: This is a SEAM forum, please ask these kind of questions in the right forum. 

          • 2. Re: Parsing XML inside JSF
            Natalie D Newbie

            Hi,


            Thank you for your exhaustive answer.


            I just wondered whether it was possible to use XPath right in the JSF page. I see I can't but it's not the thing to panic about.


            However, I miss it.


            P.S. I'll try to be more accurate next time with the forum choice.