Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-31-2007, 12:56 AM
Member
 
Join Date: Jul 2007
Posts: 4
schu777 is on a distinguished road
selectSingleNode not returning element...
I've got a simple test case and it doesn't return the element - I'm confused of what could be wrong.

Any ideas of what could be wrong? Incorrect?

Thanks, Michael

Code:
public void quickTest() { String lXml = "<OTA_HotelDescriptiveContentNotifRQ xmlns=\"http://www.opentravel.org/OTA/2003/05\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" Version=\"4.000\" PrimaryLangID=\"EN\"><HotelDescriptiveContents><HotelDescriptiveContent><HotelInfo><CategoryCodes><LocationCategory Code=\"10\" CodeDetail=\"This hotel is a resort.\" Removal=\"False\"/><SegmentCategory Code=\"1\" Removal=\"False\"/><HotelCategory Code=\"20\" Removal=\"False\"/><GuestRoomInfo Code=\"2\" CodeDetail=\"Non Smoking Rooms\" Removal=\"False\" Quantity=\"220\"/><GuestRoomInfo Code=\"1\" CodeDetail=\"Accessible Rooms\" Removal=\"False\" Quantity=\"5\"/><GuestRoomInfo Code=\"12\" CodeDetail=\"Total number of rooms\" Removal=\"False\" Quantity=\"258\"/><GuestRoomInfo Code=\"5\" CodeDetail=\"Total number of floors\" Removal=\"False\" Quantity=\"13\"/></CategoryCodes><Position Latitude=\"3213.23131\" Longitude=\"321.2132\"/><Services><Service Included=\"TRUE\" Code=\"113\" Removal=\"False\" ProximityCode=\"4\"/><Service Code=\"114\" Removal=\"False\" ProximityCode=\"1\"/><Service Code=\"115\" Removal=\"False\" ProximityCode=\"1\"/><Service Code=\"117\" Removal=\"False\" ProximityCode=\"1\"/><Service Code=\"1\" Removal=\"False\" ProximityCode=\"1\"/><Service Code=\"2\" Removal=\"False\" ProximityCode=\"2\"/><Service Code=\"3\" Removal=\"False\" ProximityCode=\"2\"/><Service Code=\"116\" Removal=\"False\" ProximityCode=\"1\"/><Service Code=\"6\" Removal=\"False\" ProximityCode=\"1\"/><Service Code=\"156\" Removal=\"False\" ProximityCode=\"1\"/><Service Code=\"4\" Removal=\"False\" ProximityCode=\"2\"/></Services><Languages><Languages LanguageCode=\"DE\"/></Languages></HotelInfo><FacilityInfo><MeetingRooms><MeetingRoom RoomName=\"Champagne Ballroom\" Removal=\"False\" ID=\"001\"><Dimension Area=\"5500\" Height=\"12\"/><AvailableCapacities><MeetingRoomCapacity MeetingRoomFormatCode=\"1\"><Occupancy MaxOccupancy=\"400\"/></MeetingRoomCapacity><MeetingRoomCapacity MeetingRoomFormatCode=\"8\"><Occupancy MaxOccupancy=\"500\"/></MeetingRoomCapacity></AvailableCapacities></MeetingRoom></MeetingRooms></FacilityInfo></HotelDescriptiveContent></HotelDescriptiveContents></OTA_HotelDescriptiveContentNotifRQ>"; try { Document lDocument = DocumentHelper.parseText(lXml); Element lTest = (Element)lDocument.getRootElement().selectSingleNode("//HotelDescriptiveContents"); Log.info("lTest", "test"); } catch (DocumentException pException) { Log.info("Exception: ", pException.toString()); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-31-2007, 02:30 AM
Senior Member
 
Join Date: Jul 2007
Posts: 134
brianhks will become famous soon enough
If I didn't know better I would say that code is C# and not Java. Am I correct? Just in case it was missed this is a Java forum.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-31-2007, 06:45 PM
Member
 
Join Date: Jul 2007
Posts: 4
schu777 is on a distinguished road
Well - it is java. Just some some method calls that my work uses to log out information...I didn't include the whole class, can if needed. The main thing this is using is Dom4j - so perhaps that is what is confusing...
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-31-2007, 07:05 PM
Senior Member
 
Join Date: Jul 2007
Posts: 134
brianhks will become famous soon enough
I've never given Dom4j much thought as there is an XML parser built in to Java. Now having a look I like it's API set much better than the standard DOM. It was parseText that threw me off. C# uses that.

Anyway as to your problem. I think it has to do with namespaces. The node you are looking for has a namespace but the XPath query does not have a namespace.

I think the solution is to add the namespace with a prefix to the document. Then use that prefix in your XPath query. Unfortunately I'm not sure how to do this.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-31-2007, 07:19 PM
Member
 
Join Date: Jul 2007
Posts: 4
schu777 is on a distinguished road
Cool - I'll take a stab at that and post the results if I get any positive ones that is...

Thanks, Michael
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help returning data from database dyn03 Database 0 03-11-2008 06:55 PM
Returning a string (Partly Bold) TampaTechGuy New To Java 3 02-03-2008 11:54 AM
JNI - passing and returning parameters by value java_to_c New To Java 0 01-31-2008 10:49 PM
How to add interceptor to persistent ejb entity to add check before returning values umen Enterprise JavaBeans 0 12-01-2007 01:55 AM
returning to a previously saved view gojava Advanced Java 0 11-09-2007 07:11 PM


All times are GMT +3. The time now is 05:29 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org