Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xml-dev] How to display content of a collection list (XML) in separate line

From: "Michael Kay" <mike@--------.--->
To: "'Jack Bush'" <netbeansfan@-----.---.-->
Date: 10/8/2008 7:45:00 AM
Your problem is no longer anything to do with JDOM or XML, 
it's just routine programming. 
 
I don't know how regular your data is, but my instinct 
would be (a) to trim() the string value of the nodes before outputting, and (b) 
to output a newline when you find a <br/> element.
 
Michael Kay
http://www.saxonica.com/


  
  
  From: Jack Bush 
  [mailto:netbeansfan@y...] 
Sent: 08 October 2008 
  06:44
To: Michael Kay
Cc: 
  xml-dev@l...
Subject: Re: [xml-dev] How to display content 
  of a collection list (XML) in separate line


  
  
  
  Hi Michael,
   
  Thanks for responding back to this question.
  The following changes have been made to overcome this issue:
   
  ( i ) XPath.selectNodes(jdomDocument, 
  "/html/body/div[@id='container']/div[@id='content']/p[11]/node()" );
  ( ii ) 
  System.out.println(((org.jdom.Content)nearest_hotels_iterator.next()).getValue());
   
  Below is the output from these change:
   
  Nearest Parks:
  Capital Hill (1.2km away)
   
  Centenial Park (3.4km away)
   
  Robertson Park (5.2km away)
   
  I have been able to alleviate those blank newlines (possibly from <br 
  />) with additional checks for no blank line prior to printing them out. 
  Nevertheless, I am wondering whether there is a better way to do this in JDOM 
  instead. In other word, I would like to get the following output:
  Nearest Parks:
  Capital Hill (1.2km away)
  Centenial Park (3.4km away)
  Robertson Park (5.2km away)
   
  Apart from this minor cosmetic preference, this solution is working 
  fine.
  Thanks again,
  Jack

  

  ----- 
  Original Message ----
From: Michael Kay <mike@s...>
To: 
  Jack Bush <netbeansfan@y...>; xml-dev@l...
Sent: 
  Wednesday, 8 October, 2008 7:30:59 AM
Subject: RE: [xml-dev] How to display 
  content of a collection list (XML) in separate line


  

  You want to iterate over the children of the p element 
  (so it's "..../p[11]/node()"), and for each node you process, if it's a 
  <br/> element then output a newline, otherwise output its string 
  value.
   
  Michael Kay
  http://www.saxonica.com/

  
    
    
    From: Jack Bush 
    [mailto:netbeansfan@y...] 
Sent: 07 October 2008 
    21:21
To: xml-dev@l...
Subject: [xml-dev] How 
    to display content of a collection list (XML) in separate 
    line


    
    
    
    Hi All,

I would like to display the content of a 
    collection list into individual line (which was captured from the following 
    XML tree) to one continuous line.


    <p>    // p[11]
<strong>Near by Parks:</strong> 
<br /> 
Capital Hill Park (1.2km away) 
<br /> 
Centenial Park (3.4km away) 
<br /> 
Robertson Park (5.2km away) 
<br /> 
.......
</p>

    

Below is the snippets that have successfully 
    parsed these contents into a collection list using JDOM:


    ( 1 )  java.util.List near_by_parks = XPath.selectNodes(jdomDocument, "/html/body/div[@id='container']/div[@id='content']/p[11]" );
( 2 )  Iterator near_by_parks_iterator = near_by_parks.iterator();
( 3 )  while (near_by_parks_iterator.hasNext())
( 4 )  {
( 5 )       System.out.println("Near by parks: " + ((org.jdom.Element)near_by_parks_iterator.next()).getTextNormalize());
( 6 )  }
 
Output from this code is:
 
Near by parks: Capital Hill Park (1.2km away)Centenial Park (3.4km away)Robertson Park (5.2km away)...
 
However, I would like the following output instead in order to assign them into different variables:
 
Near by parks: Capital Hill Park (1.2km away)
Near by parks: Centenial Park (3.4km away)
Near by parks: Robertson Park (5.2km away)
......

    It appears that it the ArrayList had incorrectly pick up 
    all the contents (incorrect XPath statement) in the first place.
    
Your advice would be much 
    appreciated.

Thanks,

Jack 

    
    Make the switch to the world's best email. Get Yahoo!7 
  Mail.

  
  Make the switch to the world's best email. Get 
  Yahoo!7 Mail.


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent