How to retrieve value of attribute using xPath ?

Hello experts,
I have a following xml chunk
<image file="/articles/engineering/boxerengine/preview_282x160.jpg">
<tout name="copyright"></tout>
<tout name="license"></tout>
<tout name="photographer"></tout>
<tout name="description"></tout>
</image>
I want to retrieve value of attribute file from absolute node image.
I tried using xpath='/image/@file' It gives output as file="/articles/engineering/boxerengine/preview_282x160.jpg"
I just want value "/articles/engineering/boxerengine/preview_282x160.jpg"
I tried using xpath='/image/@file/text()' . It does not work
Following is the java code. I am using XOM parser.
java code :
Builder parser = new Builder();
Document doc = parser.build(xmlFile);
Nodes titles = doc.query(xPath);
//xpath = ''/image/@file/text()"     
for (int i = 0; i < titles.size(); i++) {
strChunk = strChunk.append(titles.get(i).toXML());     
return strChunk.toString();
Please help.
Thanks,
Sandeep Parmar

Hi Sandeep,
Using XPath and XPathExpression you can evaluate XPath queries on Document. have a look at code given bellow:
// Building Document from XML File
org.w3c.dom.Document imageDoc = builder.parse(xmlFile);
// getting new instance of XPath
javax.xml.xpath.XPath xpath = javax.xml.xpath.XPathFactory.newInstance().newXPath();
// Building XPathExpression by compiling XPath query
javax.xml.xpath.XPathExpression xPathExp = xpath.compile("/image/@file");
// Evaluting XPath Expression on Document
String imagePath = (String) xPathExp.evaluate(imageDoc, javax.xml.xpath.XPathConstants.STRING);
// Priting image path it will print : "/articles/engineering/boxerengine/preview_282x160.jpg", if you try with data given in your post.
System.out.println(imagePath); Hope this will help.
thanks,
Tejas Purohit

Similar Messages

  • How to retrieve value from xml file

    hi all,
    can somebody pls tell me how to retrieve value from xml file using SAXParser.
    I want to retrieve value of only one tag and have to perform some validation with that value.
    it's urgent .
    pls help me out
    thnx in adv.
    ritu

    hi shanu,
    the pbm is solved, now i m able to access XXX no. in action class & i m able to validate it. The only thing which i want to know is it ok to declare static ArrayList as i have done in this code. i mean will it affect the performance or functionality of the system.
    pls have a look at the following code snippet.
    public class XMLValidator {
    static ArrayList strXXX = new ArrayList();
    public void validate(){
    factory.setValidating(true);
    parser = factory.newSAXParser();
    //all factory code is here only
    parser.parse(xmlURI, new XMLErrorHandler());     
    public void setXXX(String pstrXXX){          
    strUpn.add(pstrXXX);
    public ArrayList getXXX(){
    return strXXX;
    class XMLErrorHandler extends DefaultHandler {
    String tagName = "";
    String tagValue = "";
    String applicationRefNo = "";
    String XXXValue ="";
    String XXXNo = "";          
    XMLValidator objXmlValidator = new XMLValidator();
    public void startElement(String uri, String name, String qName, Attributes atts) {
    tagName = qName;
    public void characters(char ch[], int start, int length) {
    if ("Reference".equals(tagName)) {
    tagValue = new String(ch, start, length).trim();
    if (tagValue.length() > 0) {
    RefNo = new String(ch, start, length);
    if ("XXX".equals(tagName)) {
    XXXValue = new String(ch, start, length).trim();
    if (XXXValue.length() > 0) {
    XXXNo = new String(ch, start, length);
    public void endElement(String uri, String localName, String qName) throws SAXException {                    
    if(qName.equalsIgnoreCase("XXX")) {     
    objXmlValidator.setXXX(XXXNo);
    thnx & Regards,
    ritu

  • How to retrieve user custom attributes in OID programmatically

    Hi,
    I created a custom attribute named "location" in OID. Could someone give indication/portion of code showing how to retrieve this custom attribute "location" of a user programmatically?
    For the moment, I just found sample code (using oracle.ldap.*) showing how to retrieve "uid" attribute of a user programmatically. I tried to get me inspired of this portion of code, but never succeed.
    Thanks a lot for any help.
    Jeff

    Use below code to get all attributes in user profile including UDF.
    OIMInternalClient objOimInternalClient = null;
    User user = null;
              UserManager usrService = null;
    objOimInternalClient = new OIMInternalClient();
              if (objOimInternalClient != null) {
                        try {
                             objOimInternalClient.loginAsAdmin();
                             usrService = objOimInternalClient
                                       .getService(UserManager.class);
                             user = usrService.getDetails("usr_key", strUserKey, null);
                             endDate = (Date) user.getAttribute("End Date");
                        } catch (Exception e) {
                             e.printStackTrace();
                        } finally {
                             if (objOimInternalClient != null)
                                  objOimInternalClient.logout();
                             if (user != null)
                                  user = null;
                             if (usrService != null)
                                  usrService = null;
    In order to see all UDF's in User profile, please create Authorization Policy.

  • How to assign values to JTable using mysql database

    how to assign value to JTable using mysql...

    Search the forum. You use the values of the "ResultSet" to create a "DefaultTableModel" which you then add to the "JTable".
    I'll let you pick the search keywords to use, which I've suggested above. You can also throw in my userid if you want to specifically look for my solution.

  • How to retrieve data from MDM using java API

    hi experts
    Please explain me the step by step procedure
    how to retrieve data from MDM using java API
    and please tell me what are the
    important classes and packages in MDM Java API
    thanks
    ramu

    Hi Ramchandra,
    You can refer to following links
    MDM Java API-pdf
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/2d18d355-0601-0010-fdbb-d8b143420f49
    webinr of java API
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/89243c32-0601-0010-559d-80d5b0884d67
    Following Fourm Threads will also help.
    Java API
    Java API
    Re: usage of  java API ,
    Matching Record
    Need Java API for Matching Record
    Thanks and Regards,
    Shruti.
    Edited by: Shruti Shah on Jul 16, 2008 12:35 PM

  • Need to Set Node Attribute using XPath

    Hi,
    I have an XMLType coloum, I Need to Set/Update/Remove Root Node Attribute using XPath query.
    Regards,
    Rajesh

    Here you go:
           Node nameNode =
                    (Node) XPathFactory.newInstance().newXPath().evaluate(
                            "/root/name", doc, XPathConstants.NODE);
            nameNode.setTextContent("bob");

  • How to retrieve user defined attributes in Prepopulating a request dataset

    Hi,
    I have created couple of user defined attributes in user profile.
    And I am tryting to develop a prepopulate adapter in a request dataset for a resource. I need to prepopulate request dataset based on the values of above said user defined attributes.
    I tried to use tcResultSet result=UserOppsIntf.getSelfProfile(); in my pre-populate adapter but it is giving me only the following attributes and it is not giving any of my user defined attributes.
    Users.Manager Key
    Users.Manager Login
    Users.Manager First Name
    Users.Manager Last Name
    Users.Password Warning Date
    usr_locale
    Users.Key
    Users.Password Expired
    Users.Middle Name
    Users.User ID
    Users.Password Expiration Date
    Users.Status
    Users.Password Warned
    Users.Email
    Telephone Number
    Users.Display Name
    usr_timezone
    Users.Lock User
    Users.Last Name
    Users.First Name
    MEMBERTYPE
    If I use the code userData = usrService.getDetails("User Login", RequesterID, null); then I am getting only the following.
    Display Name:
    act_key:
    Full Name:
    usr_key:
    User Login:
    Last Name:
    First Name:
    Please let me know how to retrieve all of user defined attribute values in prepopulate adapter for a request dataset.

    Use below code to get all attributes in user profile including UDF.
    OIMInternalClient objOimInternalClient = null;
    User user = null;
              UserManager usrService = null;
    objOimInternalClient = new OIMInternalClient();
              if (objOimInternalClient != null) {
                        try {
                             objOimInternalClient.loginAsAdmin();
                             usrService = objOimInternalClient
                                       .getService(UserManager.class);
                             user = usrService.getDetails("usr_key", strUserKey, null);
                             endDate = (Date) user.getAttribute("End Date");
                        } catch (Exception e) {
                             e.printStackTrace();
                        } finally {
                             if (objOimInternalClient != null)
                                  objOimInternalClient.logout();
                             if (user != null)
                                  user = null;
                             if (usrService != null)
                                  usrService = null;
    In order to see all UDF's in User profile, please create Authorization Policy.

  • How to retrieve value of VBRK-VBELN ie. billing doc number on save of VF01

    Hi friends,
    I am working on a scenario where I need to update my custom table with values of Sales org, billign date and Billign document number on saving of VF01. I have tried using RV60AFZC include and user exit: USEREXIT_FILL_VBRK_VBRP.
    But on debugging when I save VF01, I am able to retrieve values VKORG and billing date FKDAT, but I am not able to retrieve VBRK-VBELN field. This is the billing document number.
    Can you kindly suggest me how can I retrieve my values for I can update my custom table.
    Regards
    Dolly Arora

    Hello ,
    firstly use "/h" on VF01 t-code before saving document, with on debugging mode use menu bar breakpoint at statement and write this statement "CALL CUSTOMER FUNCTION" , when you see that statement,double click them and you can go that function modules, activate begin charachter Z* customer namespace customer exits which is in function modules ,use breakpoint in this customer include programs,and activate them. you can again run with debugging mode VF01 t-code and save document  during you see VBRK-VBELN billing number,test your program be carefully ,
    regards,
    Ugur Baris Turkeli
    SAP Certified ABAP Consultant

  • How to retrieve values from the struts DAO to Struts JSP

    Hi friends,
    I have one question. i want to display values in the struts jsp file from the struts DAO class. can anyone tell how do it.
    Appreciated for your help.
    Thanks
    G1 :)

    Hi Santosh,
    Thanks for your prompt reply.
    Actually, my problem is i want to display complete rows from the DAO to JSP page. I'm displaying all the rows in the DAO from DB.
    But i dont know how to retrieve all these data from DAO. Can i take arraylist.??
    DAO:
    ------------     public Customers getData(Customers customers){ // Reading data from DB
         //ArrayList list = null ;
         try
              Connection conn = getSQLConnection();
              Statement statement = conn.createStatement();
              String qry = "select * from register";
              ResultSet resultSet = null;
              PreparedStatement pstat = conn.prepareStatement(qry);
              // pstat.setString(1, customers.getFname());
              resultSet = pstat.executeQuery();
    //Print the data to the console
    while(resultSet.next()){
              String fnam = resultSet.getString(1);
              String lnam = resultSet.getString(2);
              String gen = resultSet.getString(3);
              String addres = resultSet.getString(4);
              String cit = resultSet.getString(5);
              String zip = resultSet.getString(6);
              String county = resultSet.getString(7);
              String emal = resultSet.getString(8);
              System.out.println("First name:"+fnam);
              System.out.println("Last name:"+lnam);
              System.out.println("Address:"+addres);
              customers.setFname(fnam);
              customers.setLname(lnam);
              customers.setGender(gen);
              customers.setAddress(addres);
              customers.setCity(cit);
              customers.setZipcode(zip);
              customers.setCountry(county);
              customers.setEmail(emal);
                   statement.close();
                   conn.close();
              }catch(Exception e1){
                   e1.printStackTrace();
              return customers;
    Bean:
    I have specified in this line in Bean:
    request.getSession().setAttribute("customers", customers);
    But in JSP. how will i populate all these data. Pls..send some code.
    I'm sorry this is just practicals. i'm not doin any real time project. that;s why i have placed all these code.
    Thanks for your patience for resolving my problems.
    Thanks
    G1

  • How to set value in selectOnemenu using binding

    hi all.
    i have bind htmlSelectOneMenu. it contains some value. I want to set or display a value after a process.
    How to change value
    i have tried using setValue method of both binding property and value property of htmlSelectOneMenu.
    Same issue is with InputTextArea. how to set value in it via code(RowSelectionListener of icefaces)

    Balaji wrote:
    hi all.
    i have bind htmlSelectOneMenu. it contains some value. I want to set or display a value after a process.
    How to change value
    i have tried using setValue method of both binding property and value property of htmlSelectOneMenu.
    Same issue is with InputTextArea. how to set value in it via code(RowSelectionListener of icefaces)The html SelectOneMenu is bound to a value of a backing bean. You have to change the value of that backing bean, not the JSF component directly. JSF takes care of updating the model, you shouldn't be touching it unless you know what you are doing.

  • How to retrieve  Del. No. using MBLNR

    Hi Guyz..
    One quick Qn !
    I have MBLNR in my I_MSEG, now I want to retrieve Del. doc. no. using MBLNR. Now I tried to select VBELV as Del doc. using VBELN as subsequent doc. from  VBFA table. I am using FOR ALL ENTRIES in ITAB,
    The prob is the select on VBFA takes 5 mins for 5 record in I_MSEG.
    So how can I make this select fast or , what alternative I can use.
    here the code is
        SELECT mblnr
               line_id
               matnr
               charg
          FROM mseg
          INTO TABLE i_mseg
         WHERE matnr IN s_matnr
           AND charg IN s_charg.
       IF NOT i_mseg[] IS INITIAL.
        SELECT vbelv
               vbeln
               vbtyp_v
               vbtyp_n
          INTO TABLE i_vbfa
          FROM vbfa
           FOR ALL ENTRIES IN i_mseg
         WHERE vbeln   = i_mseg-mblnr
           AND posnn   = i_mseg-line_id
           AND vbtyp_n = 'R'
           AND vbtyp_v = 'J'.
    please help !
    Thanks
    Jaif

    Hi
    If you use all key fields in selection then you can get faster than present perfamence.
    In MSEG, below two fields also key fields.
    MJAHR
    ZEILE
    In VBFA,  VBELV, POSNV, VBTYP_N are key fields.
    Reward if it dose.
    Thanks
    Siva Kumar

  • How do I retrive date field using Xpath

    How do I retrive data,which is in date format in XML file using XPath query.
    If this is not possible, Is there any other alternative?
    Bye

    Hi,
    If suppose my xml file is like this,
    <Xml>
    <DataSet>
         <BirthDate>1-Sep-1980</BirthDate>
         <BirthDate>6-Aug-1982</BirthDate>
         <BirthDate>3-Sep-1981</BirthDate>
         <BirthDate>12-Jan-1985</BirthDate>
         <BirthDate>1-Sep-1979</BirthDate>
    </DataSet>
    </Xml>
    If I want to retrive Data,BirthDate between 1-Jan-1981 and 1-Jan-1984
    How do I do that?
    If it is not possible directly,Is there any other alternative?
    Bye

  • Any ways to retrieve value of cert using servlet

    hey..
    anyone can teach mi how to retrieve a value on a cert??i need the values in order for user to login to the system.
    For example:
    i need to know the common name of a cert so that i can authorize a user with the correspondance or valid cert can succefully login to the system.
    anyone can help mi pls??
    thx..

    try this :
    X509Certificate [] lCertList = (X509Certificate[])request.getAttribute("javax.net.ssl.peer_certificates");
    It woks fine if client authentication is require by you web server.

  • How to retrieve the content type used in a document library (C# - Client Model).

    Hello,
    I need to know if it's possible to retrieve the content type used in a document library, so I can know the columns active and used in this document library. I am using the Client Model in C#.
    Thanks

    First, retrieve your document library as a List object. Then, use the
    List.ContentTypes property to iterate through all the content types assigned to the list.
    Blog:
    blog.beckybertram.com |
    RSS | @beckybertram |
    SharePoint 2010: Six-in-One

  • How to retrieve Reconciliation Event Data using OIM API ?

    Hi,
    I want to retrieve values of some field from reconciliation event. I could not find any API method available
    to get event data.

    Check this link
    Re: API for reading reconciliation Processed-Data

Maybe you are looking for