[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Fw: Could not retrieve attributes from XML document loaded in

  • From: Jack Bush <netbeansfan@yahoo.com.au>
  • To: xml-dev@lists.xml.org
  • Date: Tue, 29 Jun 2010 01:04:25 -0700 (PDT)

Fw:  Could not retrieve attributes from XML document loaded in
Hi All,

Looks like the jdomXmlDocument was missing on line 6 so see whether you could help figure out where the issue is.

Thanks a lot,

Jack


----- Forwarded Message ----
From: Jack Bush <netbeansfan@yahoo.com.au>
To: xml-dev@lists.xml.org
Sent: Mon, 28 June, 2010 11:15:46 PM
Subject:  Could not retrieve attributes from XML document loaded in JDOM

Hi All,
 
I am having difficulty reading and parsing the following XML City.xml document using Saxon parser and XPath:
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional/ /EN" "http://www. w3.org/TR/ xhtml1/DTD/ xhtml1-transitio nal.dtd">
<html xmlns="http: //www.w3. org/1999/ xhtml">
    <head>
        <meta http-equiv=" Content-Type" content="text/ html; charset=UTF- 8" />
        ……..
    </head>
    <body>
        <div id="content">
            <table class="sresults">
                <tr>
                    <td>
                        <a href="http:/ /www.abc.com/areas" title=" Hollywood , CA "> hollywood </a>
                    </td>
                    <td>
                        <a href="http:/ /www.abc.com/areas" title=" San Jose , CA "> san jose </a>
                    </td>
                    <td>
                        <a href="http:/ /www.abc.com/areas" title=" San Francisco , CA "> san francisco </a>
                    </td>
                    <td>
                        <a href="http:/ /www.abc.com/areas" title=" San Diego , CA "> San diego </a>
                    </td>
                </tr>
              ……….
        </body>
</html>
 
Below is the code snippets that illustrates how I tried to retrieve the attribute title of <a>:
 1. BufferedReader incomingbrXml = new BufferedReader(new FileReader("C:\City.xml"));
2. SAXBuilder saxBuilder = new SAXBuilder(false);
3. Document jdomXmlDocument = saxBuilder.build(incomingbrXml);4. String city_content = null;
5. XPath cityXPath = XPath.newInstance("/ns:html/ns:body/ns:div[@id='content']/ns:table[@class='sresults']/ns:tr/ns:td/ns:a/@title");
6. java.util.List cityList = cityXPath.selectNodes(jdomXmlDocument);
7. Iterator city_iterator = cityList.iterator();
8. while (city_iterator.hasNext()) { 
9.     city_content = ((org.jdom.Attribute)city_iterator.next()).getValue();
10.   if (city_content.length() != 0) {
11.       System.out.println("Area Url:" + area_content.toString()); }
12. }
 
I would like to get the following output:
 
Hollywood , CA
San Jose , CA 
San Francisco , CA 
San Diego , CA 
 
Instead, the 
 I am running JDK 1.6.0_17, Netbeans 6.7, JDOM 1.1, Saxon9.1 on Windows XP platform.
Any assistance would be appreciated.
Thanks in advance,
JackjdomXmlDocument);jdomXmlDocument is made up of only the first few lines of City.xml and nothing on the body when debugging in Netbeans. I am running this program online so there would not be an issue with entity resolver that took place on line 2.





_______________________________________________________________________

XML-DEV is a publicly archived, unmoderated list hosted by OASIS
to support XML implementation and development. To minimize
spam in the archives, you must subscribe before posting.

[Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
Or unsubscribe: xml-dev-unsubscribe@lists.xml.org
subscribe: xml-dev-subscribe@lists.xml.org
List archive: http://lists.xml.org/archives/xml-dev/
List Guidelines: http://www.oasis-open.org/maillists/guidelines.php






[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.