Running the Application
Once you have the source code compiled and linked, it can be run connecting to the database specified by your ORACE_SID environment setting and using the HR/HR userID/Password. The following is an example command line with its result.
selectxpq “select XMLELEMENT("EmployeeList", XMLAGG(XMLELEMENT("Employee",
XMLATTRIBUTES( employee_id AS "EmpID"), XMLELEMENT("Name", first_name
|| ' '|| last_name), XMLELEMENT("Salary", salary))))AS result FROM
hr.employees where Salary > 13000” “//Employee/Name[../Salary="17000"]”
This query returns the following XML document from the employees table:
<EmployeeList>
<Employee EmpID="100">
<Name>Steven King</Name>
<Salary>24000</Salary>
</Employee>
<Employee EmpID="101">
<Name>Neena Kochhar</Name>
<Salary>17000</Salary>
</Employee>
<Employee EmpID="102">
<Name>Lex De Haan</Name>
<Salary>17000</Salary>
</Employee>
<Employee EmpID="145">
<Name>John Russell</Name>
<Salary>14000</Salary>
</Employee>
<Employee EmpID="146">
<Name>Karen Partners</Name>
<Salary>13500</Salary>
</Employee>
</EmployeeList>
The XPath expression //Employee/Name[../Salary="17000"] asks for all the names of employees whose salary is equal to 17000 and returns the following XML fragment:
<Name>Neena Kochhar</Name>
<Name>Lex De Haan</Name>