Results 1 to 5 of 5
  1. #1
    schu777 is offline Member
    Join Date
    Jul 2007
    Posts
    4
    Rep Power
    0

    Default 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

    Java 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());
    		}
    	}

  2. #2
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    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.

  3. #3
    schu777 is offline Member
    Join Date
    Jul 2007
    Posts
    4
    Rep Power
    0

    Default

    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...

  4. #4
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    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.

  5. #5
    schu777 is offline Member
    Join Date
    Jul 2007
    Posts
    4
    Rep Power
    0

    Default

    Cool - I'll take a stab at that and post the results if I get any positive ones that is...

    Thanks, Michael

Similar Threads

  1. Replies: 0
    Last Post: 03-11-2008, 05:55 PM
  2. Returning a string (Partly Bold)
    By TampaTechGuy in forum New To Java
    Replies: 3
    Last Post: 02-03-2008, 10:54 AM
  3. JNI - passing and returning parameters by value
    By java_to_c in forum New To Java
    Replies: 0
    Last Post: 01-31-2008, 09:49 PM
  4. Replies: 0
    Last Post: 12-01-2007, 12:55 AM
  5. returning to a previously saved view
    By gojava in forum Advanced Java
    Replies: 0
    Last Post: 11-09-2007, 06:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •