I am new to XPATH and I have to convert a string containing an XML tree into
a document then search the document for specific elements and attribute
values.
Here's a small example of my code...  I just do not know how to access the
values of the FirstName, LastName elements and the '@Type' attributes of
these..

Please help.  Thank you.
Greg

-- XML --

<CAP>
  <RelationshipRecord>
    <Customer>
      <CustomerID/>
      <NameDetails>
        <PersonName>
          <FirstName Type='Contains'/>
          <LastName Type='BeginsWith'>Adl</LastName>
       </PersonName>
      </NameDetails>
      <AddressDetails AddrType='Directory'>
        <Country>
          <CountryName>United States</CountryName>
          <AdministrativeArea Type='State'>
            <AdministrativeAreaName Type='Code'/>
            <Locality Type='BeginsWith'/>
            <PostalCode Type='BeginsWtih'>606</PostalCode>
          </AdminstrativeArea>
        </Country>
      </AddressDetails>
    </Customer>
  </RelationshipRecord>
</CAP>

-- code --

// create the document from the string
Document parmDoc = DocumentHelper.parseText( xSearchParms );
searchPath =
"//Parms/CAP/RelationshipRecord/Customer/NameDetails/PersonName";

// last name

Node nodePersonName = parmDoc.selectSingleNode( searchPath );
String lName = nodePersonName.valueOf( "LastName" );
String lNameAttrib = nodePersonName.valueOf( "@Type" );
        
// first name   
Node nodeFname = parmDoc.selectSingleNode( searchPath + "/FirstName" );
String fName = nodeFname.valueOf( "FirstName" );
String fNameAttrib = nodeFname.valueOf( "@Type" );

// country
searchPath = "//Parms/CAP/RelationshipRecord/Customer" +
"/AddressDetails/Country";
Node nodeCountry = parmDoc.selectSingleNode( searchPath );
String country = nodeCountry.valueOf( "CountryName" );

// city
searchPath = searchPath + "/AdministrativeArea[ @Type='State' ]";
Node nodeCity = parmDoc.selectSingleNode( searchPath );
String city = nodeCity.valueOf( "Locality" );
String cityAttrib = nodeCity.valueOf( "@Type" );



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to