Getting the value of an element using the attribute value

I have a Document object and I want to get the value from the element that has an attribute value of "college". Does that make sense?
<TEAM>
     <FIELD name="city">Phoenix</FIELD>
                    <SECTION name="NASH">
                          <FIELD name="college">Santa Clara</FIELD>
                          <FIELD name="grad">1997</FIELD>
                          <FIELD name="years">9</FIELD>
                          <FIELD name="PPG">19.2</FIELD>
                         <FIELD name="AST">10.4</FIELD>
                        <FIELD name="REB">4.2</FIELD>
        </SECTION>
</TEAM>
Thanks!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

I have a Document object and I want to get thevalue
from the element that has an attribute value of
"college". Does that make sense?
<TEAM>
     <FIELD name="city">Phoenix</FIELD>
<SECTION name="NASH">
<FIELD name="college">Santa
FIELD name="college">Santa Clara</FIELD>
<FIELD
<FIELD name="grad">1997</FIELD>
<FIELD
<FIELD name="years">9</FIELD>
<FIELD
<FIELD name="PPG">19.2</FIELD>
<FIELD
<FIELD name="AST">10.4</FIELD>
<FIELD
<FIELD name="REB">4.2</FIELD>
</SECTION>
</TEAM>
Thanks!
/TEAM/SECTION/FIELD[@name='college']
if you just want the text then:
/TEAM/SECTION/FIELD[@name='college']/text()

Similar Messages

  • Runtime error to get the attribute value of an element

    mydoc.xml
    =========
    <?xml version = "1.0"?>
    <persons>
         <person name="Joe" age="22" />
    </persons>
    In mydox.xml, I want to get the attribute values of element person. Of course,
    in the actual XML file, it is more complicated.
    However, I get the following run-time error,
    Exception in thread "main" java.lang.NullPointerException
    at ParserTest.main(ParserTest2.java:18) on line element.hasAttribute("name")
    import java.io.*;
    import javax.xml.transform.*;
    import javax.xml.transform.dom.*;
    import javax.xml.transform.stream.*;
    import org.w3c.dom.*;
    import javax.xml.parsers.*;
    import org.xml.sax.*;
    public class ParserTest2
         public static void main(String[] args) throws ParserConfigurationException, SAXException
              String xmlFile = "mydoc.xml";
              doc = getDocumentFromFile(xmlFile);
              Element element = doc.getElementById("person");
              //Exception in thread "main" java.lang.NullPointerException
              if (element.hasAttribute("name"))
              {     System.out.println("attribute = " + element.getAttribute("name"));
         public static Document getDocumentFromFile(String xmlFile)
                   try
                        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                        DocumentBuilder builder = factory.newDocumentBuilder();
                        Document doc = builder.parse(new File(xmlFile));
                        return doc;
                   catch(IOException e)
                   {     e.printStackTrace();
                        return null;
                   catch(SAXException e)
                   {     e.printStackTrace();
                        return null;
                   catch(ParserConfigurationException e)
                   {     e.printStackTrace();
                        return null;
         private static Document doc;
    any ideas? Thanks!!

    [url http://java.sun.com/j2se/1.4.2/docs/api/java/lang/NullPointerException.html]java.lang.NullPointerException
    Thrown when an application attempts to use null in a case where an object is required. These include:
    Calling the instance method of a null object.
    Accessing or modifying the field of a null object.
    Taking the length of null as if it were an array.
    Accessing or modifying the slots of null as if it were an array.
    Throwing null as if it were a Throwable value.
    You know what line it happens on, so you know which of these cases applies. So you know that variable "element" is null at that point. How could it come to be null? You assign to it only once, two lines above. How could that assignment be null? Check the documentation for [url http://java.sun.com/j2se/1.4.2/docs/api/org/w3c/dom/Document.html#getElementById(java.lang.String)]org.w3c.dom.Document.getElementById().
    Repeat every time you get one of those exceptions.

  • How to get the attribute value of an XML file??

    How to get the attribute value of an XML file??
    For example, how to get name and age attributes?
    <student name="Joe" age="20" />

    What are you using to read the XML file??
    On the assumption of JDOM - www.jdom.org. Something along the lines of:SAXBuilder builder = new SAXBuilder(true);
    Document doc = builder.build(filename);
    Element root = doc.getRootElement();
    List children = root.getChildren();
    Element thisElement = (Element)children.get(n);
    String name = thisElement.getAttributeValue("name")
    try
         int age = Integer.parseInt(thisElement.getAttributeValue("age"));
    catch (Exception ex)
         throw new InvalidElementException("Expected an int.....");
    }Ben

  • How to get the attribute values out?

    Hi everyone,
    <root>
    <category name="Mens Clothing" id="0">
    <subcategory>Active/Baselayer Tops</subcategory>
    <subcategory>Active/Baselayer
    Bottoms</subcategory>
    </category>
    <category name="Womens Clothing" id="1">
    <subcategory>aaa</subcategory>
    <subcategory>bbb</subcategory>
    </category>
    </root>
    How to get the attribute values out? For example "Mens
    Clothing" and "Womens Clothing".
    // the line below returns "Active/Baselayer Tops" and
    "Active/Baselayer Bottoms"
    var myXml:XML = new XML(event.result);
    Thanks,
    May

    Here is attribute identifier operator from FB Help:
    @ attribute identifier Operator
    Usage myXML.@attributeName
    Identifies attributes of an XML or XMLList object. For
    example, myXML.@id identifies attributes named id for the myXML XML
    object. You can also use the following syntax to access attributes:
    myXML.attribute("id"), myXML["@id"], and myXML.@["id"]. The syntax
    myXML.@id is recommended. To return an XMLList object of all
    attribute names, use @*. To return an attribute with a name that
    matches an ActionScript reserved word, use the attribute() method
    instead of the @ operator.
    Operands attributeName:* — The name of the attribute.
    Example
    How to use examples
    The first example shows how to use the @ (at sign) operator
    to identify an attribute of an element:
    var myXML:XML =
    <item id = "42">
    <catalogName>Presta tube</catalogName>
    <price>3.99</price>
    </item>;
    trace(myXML.@id); // 42The next example returns all attribute
    names:
    var xml:XML =<example id='123' color='blue'/>
    var xml2:XMLList = xml.@*;
    trace(xml2 is XMLList); // true
    trace(xml2.length()); // 2
    for (var i:int = 0; i < xml2.length(); i++)
    trace(typeof(xml2
    )); // xml
    trace(xml2.nodeKind()); // attribute
    trace(xml2
    .name()); // id and color
    } The next example returns an attribute with a name that
    matches a reserved word in ActionScript. You cannot use the syntax
    xml.@class (since class is a reserved word in ActionScript). You
    need to use the syntax xml.attribute("class"):
    var xml:XML = <example class='123'/>
    trace(xml.attribute("class"));

  • In Jsp TagLib how can I get the Attribute value (like JavaBean) in jsp

    Dear Friends,
    TagLib how can I get the Attribute value (like JavaBean) in jsp .
    I do this thing.
    public void setPageContext(PageContext p) {
              pc = p;
    pc.setAttribute("id", new String("1") );
              pc.setAttribute("first_name",new String("Siddharth")); //,pc.SESSION_SCOPE);
              pc.setAttribute("last_name", new String("singh"));
    but in Jsp
    <td>
    <%=pageContext.getAttribute("first_name"); %>
    cause null is returing.
    Pls HELP me
    with regards
    Siddharth Singh

    First, there is no need to pass in the page context to the tag. It already is present. How you get to it depends on what type of tag:
    Using [url http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/jsp/tagext/SimpleTagSupport.html]SimpleTagSupport
    public class MyTag extends SimpleTagSupport
      public void doTag()
        PageContext pc = (PageContext)getJspContext();
        pc.setAttribute("first_name", "Siddharth");
        pc.setAttribute("last_name", "Singh");
        pc.setAttribute("id", "1");
    }Using [url http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/jsp/tagext/TagSupport.html]TagSupport or it's subclass [url http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/jsp/tagext/BodyTagSupport.html]BodyTagSupport the page context is aleady declared as an implicit object:
    public class MyTag extends TagSupport
      public void doStartTag()
        pageContext.setAttribute("first_name", "Siddharth");
        pageContext.setAttribute("last_name", "Singh");
        pageContext.setAttribute("id", "1");
    }In each case, this sort of thing should work:
    <mytags:MyTag />
    <%= pageContext.getAttribute("first_name") %>I

  • Getting the attributes of an object by using a URL

    Hi,
    Here is my problem. I want to access to the attributes of an object stored in an LDAP. I know this object when I receive this kind of url:
    ldap://163.187.83.145:389/ou=People,dc=slb,dc=com,uid=TOTO;
    How can I get the attributes of the uid without changing the code below. If I set the context_provider with this url, I am pointing on the right object but my problem is to get its attributes.
    Does anyone know how to do?
    Here is an example of my code:
    String ldap_URL = ldap://163.187.83.145:389/ou=People,dc=slb,dc=com,uid=TOTO;
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, ldap_URL);

    Hello !!
    You can very well carry on with your code , to get the attributes you can have a look at this code snippet :
    import java.io.*;
    import java.util.Hashtable;
    import javax.naming.*;
    import javax.naming.directory.*;
    class GetAttr {
         public static void main(String args[]) {
              Hashtable env = new Hashtable();
              String attname=null;
    String ldap_URL="ldap://163.187.83.145:389/ou=People,dc=slb,dc=com,uid=TOTO";
              env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
              env.put(Context.PROVIDER_URL, ldap_url);
              try {
                   DirContext ctx = new InitialDirContext(env);
                   String[] strAttrID={"objectClass","cn","userPassword"};
                   Attributes attrs = ctx.getAttributes("",strAttrID);
                   for (
                        NamingEnumeration ae = attrs.getAll();
                   ae.hasMore();
                   Attribute attr = (Attribute)ae.next();
                   System.out.println("\n" + attr.getID());
                   for (
                             NamingEnumeration e = attr.getAll();
                             e.hasMore();
                             System.out.print(" : " + e.next() +"\t")
              catch (NamingException ne) {
                   ne.printStackTrace();
    1.See this line ctx.getAttributes("",strAttrID)....this means that in the URL itself you have given JNDI the complete reference or key to locate the object. For eg: if uid=TOTO was not present in your URL , you could have done ctx.getAttributes("uid=TOTO",strAttrID).
    2.This will print only the 3 attributes I have specified(objectclass,cn,password).You can add your own according to the attributes u have in your LDAP directory (see in LDIF.txt or <some-name>.ldif)
    Hope this helps
    Regards
    Chandu

  • How can I get the attribute of another app of the JSP server's session

    in one server, use Tomcat 4.1, have two application at
    .../webapps/app1
    .../webapps/app2
    when use login to application1, it'll set a attribute of session use following code:
    session.setAttribute("identitycode", IdentityCode);
    session.setMaxInactiveInterval(SessionTimeOut);
    and the other jsp programs which at app1 directory will try to get the attribute of this session to identity whether the user had login and get the identity code.
    I want to make user just login one time to use application1 and application2, but I didn't know how to get the attribute of session what seted at app1 in app2's programs.
    can you tell me how I can do this?

    If there are 2 different applications like app1 & app2, U need to use:
    application.setAttribute() method.(not session.getAttribute).
    u need to maintain one collection like hash table which will store the mappings of User & their IDs . U can then get the user details from app1 to app2

  • How to get the Attributes of the UNIX  file Directories  ?

    Hi Guru,
    How to find of the Attributes of the UNIX  file Directories in sap  TC  :-   u2018 *ZZWT*u2019   .
    The file attribute details need to show in the report.
    I try on FM : EPS_GET_FILE_ATTRIBUTES
                       /SDF/GET_FILE_INFO
    But not getting the attributes details.
    If any idea plz. Help me.
    Regards,
    Subash

    Which basis release do you use?
    From 7.0 you have [GET DATASET|http://help.sap.com/abapdocu_70/en/ABAPGET_DATASET.htm] statement
    Before, you may only get what you see in AL11 : mimic what is in program RSWATCH0
    Or you may register and use [UNIX commands (SM69 transaction / SXPG|http://help.sap.com/saphelp_nw70/helpdata/en/fa/0971e1543b11d1898e0000e8322d00/frameset.htm]) and get the results
    Edited by: Sandra Rossi on Aug 2, 2009 12:39 AM

  • Getting the attributes of an AttributedString

    Hi,
    well the title says it all: How can I get the attributed of an AttributedString. I treat the whole AttributedString as an entity
    so I don't need the attributes of a single char, they all have the same attributes.
    Thanks,
    Mohamz

    You would use an AttributedCharacterIterator, but the run for all attributes in the iterator will be the whole string. Chuck away the iterator without iterating it.

  • How can I get the attributes details like user name, mail , from sAMAccount csv or notepad file through powershell or any other command in AD?

    How can I get the attributes details like user name, mail , from sAMAccount csv or notepad file through powershell or any other command in AD?

    Ok what about If i need to get all important attributes by comparing Email addresses from excel file and get all required answers
    currently I am trying to verify how many users Lines are missing , Emp numbers , Phones  from AD with HR list available to me.
    I am trying to Scan all the AD matching HR Excel sheet and want to search quickly how many accounts are active , Line Managers names , Phone numbers , locations , title , AD ID .
    these are fields I am interested to get in output file after scanning Excel file and geting reply from AD in another Excel or CSV file
    Name’tAccountName’tDescri ption’tEma I IAddress’tLastLogonoate’tManager’tTitle’tDepartmenttComp
    any’twhenCreatedtAcctEnabled’tGroups
    Name,SamAccountName,Description,EmailAddress,LastLogonDate,Manager,Title,Department,Company,whenCreated,Enabled,MemberOf | Sort-Object -Property Name
    Can you modify this script to help me out :)
    Hi,
    Depending on what attributes you want.
    Import-Module ActiveDirectory
    #From a txt file
    $USERS = Get-Content C:\Temp\USER-LIST.txt
    $USERS|Foreach{Get-ADUser $_ -Properties * |Select SAMAccountName, mail, XXXXX}|Export-CSV -Path C:\Temp\USERS-ATTRIBUTES.csv
    #or from a csv file
    $USERS = Import-CSV C:\Temp\USER-LIST.csv
    $USERS|Foreach{Get-ADUser $_.SAMAccountName -Properties * |Select SAMAccountName, mail, XXXXX}|Export-CSV -Path C:\Temp\USERS-ATTRIBUTES.csv
    Regards,
    Dear
    Gautam Ji<abbr class="affil"></abbr>
    Thanks for replying I tried both but it did not work for me instead this command which i extended generated nice results
    Get-ADUser -Filter * -Property * | Select-Object Name,Created,createTimeStamp,DistinguishedName,DisplayName,
    EmployeeID,EmployeeNumber,Enabled,HomeDirectory,LastBadPasswordAttempt,LastLogonDate,LogonWorkstations,City,Manager,MemberOf,MobilePhone,PasswordLastSet,BadLogonCount,pwdLastSet,SamAccountName,UserPrincipalName,whenCreated,whenChanged
    | Export-CSV Allusers.csv -NoTypeInformation -Encoding UTF8
    only one problem is that Manager column is generating this outcome rather showing exact name of the line Manager .
    CN=Mr XYZ ,OU=Users,OU=IT,OU=Departments,OU=Company ,DC=organization,DC=com,DC=tk

  • OID-23054 Error: failure getting the attribute

    Hi,
    I have set up OID replication among three servers. One server being the Supplier, and the rest two are Consumers. The replication is working fine but one of the consumer is applying the replication way later than the other consumer. After looking at the logs, I'm seeing the below error messages constantly. One of the consumers transport, and apply the changes instantaneously and without any errors. But, the other consumer transport the change instantly but takes time to apply it. Before applying, the below error messages are shown. All other settings are identical.
    ERROR:
    [2011-06-09T12:22:42-07:00] [OID] [ERROR:8] *[23054]* [OIDREPLD] [host: testhost.xxxx.local] [pid: 25843] [tid: 2] Reader(Apply):: In gslrrcaChangeLogProc, failure getting the attribute=orcllastappliedchangenumber;apply$prodhost_xxxx$testhost_xxxx from the changeStatusEntry. Server=prodhost_xxxx, agreement=orclagreementid=000005,orclreplicaid=prodhost_xxxx,cn=replication configuration, operation=APPLY.
    The fusion middleware error message document says the following about the error:
    OID-23054: In %s, failure getting the attribute=%s from the changeStatusEntry. Server=%s, agreement=%s, operation=%s.
    Cause: Invalid changestatusentry DN.
    Action: Contact Oracle Support Services
    Versions:
    IDM 11.1.1.4.0
    DB 11.2.0.2.0
    WebLogic 10.3.4
    Thanks,
    Raj

    I am facing the same error. I am talking to oracle OId Engineer about it. I will update the outcome.
    Thanks,
    Vivek

  • Getting the attribute value from a table from page def using el expression.

    Hi,
    Am using Jdeveloper 11.1.2.0.0 and have a requirement as follows for which a sample is been created. Requirement is as follows..
    1. Have a Taskflow that has a readonly table Employee.
    2. On clicking of a button called "route" checks if the selected row , Manager id attribute value = 200 then navigate to first page else if manager id attribute value is 200 then navigate to second page.
    Through the page def , if it has form , then we can access the attributes like #{data.view_FirstPageDef.ManagerId} . In case of acquiring the same attribute value from table using page def ? is what am unable to get..
    Have achieved the routing concept using the Router activity on Taskflow. But am unable to get the selected row attribute value of a table from the employee page def.. Can someone suggest on the same...
    Thanks and Regards,
    Vinitha G

    On the router, right click its icon in the task flow and create a page definition. Then in the page def file, add an iterator based on the same View Object from the table in the first page, then add a value attribute mapped to managerId in the View Object iterator. Finally in the router you can write EL expressions along the lines of #{bindings.ManagerId.inputValue = 200} or #{bindings.ManagerId.inputValue != 200}.
    CM.

  • How can I get the Attribute Value in the existing XML Elements-Reg.

    Dear All,<br /><br />  I have the InDesign Document with xml Based, now I want to get the XML Elements name and XML Attributes for each Elements, using SDK Concepts. <br /><br />Example:<br /><br /> <chapter>  chapter1 </chapter> id = "ch001"<br /> <sec> Section ....</sec> id ="se001"<br /> <para> para ....</para> id="pa001"<br /><br />How can I get the XMLElements & XML Attributes in the InDesign-XML Structure.<br /><br />Please  any one can suggest me....<br /><br />Thanks & Regards<br />T.R.Harihara SudhaN

    Dear Dirk
    Many Thanks for the Suggestions, Now I search and study the XML concepts. Meanwhile, I need your suggestions for further Development in SDK -XML concepts.
    I am using the SnippetRunner -SDK file, their given some XML based programmes. [Create XML Elements, Elements + Attributes, XML Comments] and etc...
    Hope U will help me to Develop the SDK- XML Concepts.
    Thanks & Regards
    T.R.Harihara SuduhaN

  • ADF: How to get the attributes' values of one single row from a table?

    Currently I have a table with 3 attributes, suppose A,B and C respectively. And I've added an selectionListener to this table. That means when I select one single row of this table, I wish to get the respective value of A, B and C for that particular row. How do I achieve this?
    suppose the method is like:
    public void selectionRow(SelectionEvent se) {            //se is the mouse selection event
    .......??? //what should I do to get the values of A\B\C for one single row?
    Edited by: user12635428 on Mar 23, 2010 1:40 AM

    Hi
    Assuming you are using Jdev 11g.
    Try with this
    public void selectionRow(SelectionEvent se) {
    String val = getManagedBeanValue("bindings.AttributeName.inputValue");
    public static Object getManagedBeanValue(String beanName) {
    StringBuffer buff = new StringBuffer("#{");
    buff.append(beanName);
    buff.append("}");
    return resolveExpression(buff.toString());
    public static Object resolveExpression(String expression) {
    FacesContext facesContext = getFacesContext();
    Application app = facesContext.getApplication();
    ExpressionFactory elFactory = app.getExpressionFactory();
    ELContext elContext = facesContext.getELContext();
    ValueExpression valueExp =
    elFactory.createValueExpression(elContext, expression,
    Object.class);
    return valueExp.getValue(elContext);
    Vikram

  • Get the attributes NAME and VALUE from an XML

    I really love this forum :)
    I load an XML an populate a Tree, from which I start to drag
    items.
    the xml looks like this:
    <myTag attrName="attrValue"
    otherAttrName="otherAttrValue"/>
    var ds:DragSource = event.dragSource;
    var var1:String =(event.dragInitiator as
    Tree).value.@attrName;
    -> the var1 variable has now: "attrValue"
    my question is.. how can I get all the attributes' names? in
    this example: attrName and otherAttrName (suppose I don't know the
    structure of that xml node)
    what about attributes values?
    thank you!

    The snippet below takes an xml node(nodeCur), loops over the
    attributes list and builds an array that contains the attribute
    name and value for each attribute. It comes from a sample app that
    allows you to edit an xml file.
    Sorry that the forum will remove the formatting
    var aDPAttributes:Array = new Array();
    var xlAttributes:XMLList = nodeCur.@*;
    var attribute:Attribute;
    for ( var i:int = 0; i < xlAttributes.length(); i++) {
    aDPAttributes.push({name:xlAttributes [ i ]
    .name(),value:xlAttributes [ i ] });
    dgAttributes.dataProvider = aDPAttributes; //set the property
    sheet dataProvider
    Tracy

  • Not able to get the attributes from HttpSession

    hi all,
    i'm using session.setAttribute() in a jsp to put an attribute in the session and when i try to get that attribute in another jsp it's not giving the value. But the getAttribute() mehods is giving the value in the same jsp page where i used the setAttribute() method.
    pls help,
    regards chandu

    If you are using IE go to tool and then internet options and look under privacy for you cookie status(this will vary version).
    To use URL rewriting all you have to do is one of two things:
    www.url.com?parm=value&param2=value
    or if the value is a result of a java expression or is a java variable you can do
    www.url.com?parm=<%=variable%>&param2=<%=(variable +1)%>
    You get the values from url rewriting by using request.getParameter or getParameterValues(used when multiple values are getting passed).
    When data is retrieved using getParameter it always comes back as a string and you should trim them as well.
    HTH,
    J.Clancey

Maybe you are looking for