GET element(s) by an attributes value
Hi,
Is it possible to get an element of a node by the value of 1 attribute?
I know there is a method getelement() where you can specify an index,but I don't find a method where you can specify the attribute's name and value.
Now I have to loop trough all elements and check it's the element I need.
Friendly regards,
Nick
Yes.
We just get the element by attribute value like you: Loop all the elements and check the element's attribute value...
As far as i know, we have not the simple method to get the element by only one attribute value...
If you have, pls tell us and you are very appreciated.
Best wishes.
Similar Messages
-
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() -
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. -
Get element based on attribute value
Hi,
I need to locate an element based on its unique
attribute value. There are lots of elements in the
hierarchy, I only show relavant ones here.
code:
<myElement myAttribute="attValue">
<childElement>child value</childElement>
</myElement>
If "attValue" is unique for all elements, and I want to
locate myElement and then get childElement value.
I did the following, but it does not work:
<xsl:value-of select="//*[myAttribute='attValue']/childElement"/>
Could any one see what I did wrong?
regards,Thanks for spotting the error. I was too careless.
What if I want to use a xsl:variable to do the testing, can I do the following:
<xsl:variable name="uniqueAttValue" <xsl:value-of select="..."/></xsl:variable>
<xsl:value-of select="//*[@myAttribute={$uniqueAttValue}]/childElement"/>
I used either {$uniqueAttValue} or '{$uniqueAttValue}', but neither works. -
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 -
I have a provider hosted app in sharepoint which works locally without problem. I followed this tutorial to publish it to azure
http://blogs.technet.com/b/sharepointdevelopersupport/archive/2013/09/05/how-to-deploy-a-provider-hosted-app-as-an-azure-site.aspx
However after publishing the webservice doesnt work I get this exception:
[InvalidOperationException: The type 'x.IntranetWeb.Services.AppEventReceiver', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.]
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +62739
System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +1429
System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +52
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +598
[ServiceActivationException: The service '/Services/AppEventReceiver.svc' cannot be activated due to an exception during compilation. The exception message is: The type 'x.IntranetWeb.Services.AppEventReceiver', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found..]
System.Runtime.AsyncResult.End(IAsyncResult result) +486572
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +174
System.ServiceModel.Activation.ServiceHttpModule.EndProcessRequest(IAsyncResult ar) +345998
System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +9683593
My web.config which I didnt touch.
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="ClientId" value="xx-04e7-4caf-854a-89c20577d7da" />
<add key="ClientSecret" value="ljguTvxHR+xx+Pl1IMg1Hjt5rsQ=" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<customErrors mode="Off"/>
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<!--Used by app for SharePoint-->
<binding name="secureBinding">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<protocolMapping>
<add binding="basicHttpBinding" scheme="https" bindingConfiguration="secureBinding" />
</protocolMapping>
</system.serviceModel>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
</configuration>
and a piece of the code of the remote event receiver
<%@ ServiceHost Language="C#" Debug="true" Service="x.IntranetWeb.Services.AppEventReceiver" CodeBehind="AppEventReceiver.svc.cs" %>
namespace x.IntranetWeb.Services
public class AppEventReceiver : IRemoteEventService
Follow me on Twitter
levalencia BlogHi,
The issue here is the mapping of the interface to the service in question, and usually points to a possible mistype or rename of something within your service architecture.
You need to make sure your namespace and service name here match your service name itself.
For detailed information, you could refer to:
https://haddicus.wordpress.com/2011/06/06/service-attribute-value-not-found-wcf-services/
http://stackoverflow.com/questions/9557221/the-type-restservice-weddingservice-provided-as-the-service-attribute-value-i
Regards -
How to get attribute value of a node
Hi experts
I have a mapped node in my view context from component controller context. This node consists of 2 value attributes inside
Example:
NODE1 -
> Cardinality 1..1, seleciton 1..1
-- x_date -
> type DATS
-- x_years -
> dec3
How do I get the attribute value attr1 and attr2 ??
Here is my code in my view method
DATA: lr_node_info TYPE REF TO if_wd_context_node_info,
l_date TYPE dats,
l_xyears TYPE i.
lr_node_info = wd_context->get_node_info( ).
lr_node_info = lr_node_info->get_child_node('NODE1').
l_date = lr_node_info->get_attribute( name = 'X_DATE' ).
l_xyears = lr_node_info->get_attribute( name = 'X_YEARS' ).
It does not seems to work since it says < the result type of the function method can not be converted into the result type L_DATE>
I try to understand why but not sucessful, please help and thank you for your kindnessHi Dean,
Regading uour problem of reading the attributes value of the context node, you have to use the code wizard. that ia avaliable on the top toolbar when you are inside the View Method
There is option to read context select that radio button option and then thru F4 help
if you can select the node then Code is automatically generated with variable declaration.!!
Like this :
DATA lo_nd_node1 TYPE REF TO if_wd_context_node.
DATA lo_el_node1 TYPE REF TO if_wd_context_element.
DATA ls_node1 TYPE wd_this->element_node1.
DATA lv_x_date LIKE ls_node1-x_date.
DATA lv_x_year LIKE ls_node1-x_year.
navigate from <CONTEXT> to <NODE1> via lead selection
lo_nd_node1 = wd_context->get_child_node( name = wd_this->wdctx_node1 ).
get element via lead selection
lo_el_node1 = lo_nd_node1->get_element( ).
get all declared attributes
lo_el_node1->get_static_attributes(
IMPORTING
static_attributes = ls_node1 ).
lv_x_date = ls_node1-x_date.
lv_x_date = ls_noe1-x_year.
if you can select the attribute then Code is automatically generated with variable declaration.!!
DATA lo_nd_node1 TYPE REF TO if_wd_context_node.
DATA lo_el_node1 TYPE REF TO if_wd_context_element.
DATA ls_node1 TYPE wd_this->element_node1.
DATA lv_x_date LIKE ls_node1-x_date.
navigate from <CONTEXT> to <NODE1> via lead selection
lo_nd_node1 = wd_context->get_child_node( name = wd_this->wdctx_node1 ).
get element via lead selection
lo_el_node1 = lo_nd_node1->get_element( ).
get single attribute
lo_el_node1->get_attribute(
EXPORTING
name = `X_DATE`
IMPORTING
value = lv_x_date ).
Hopes this will helps you.
Regard
Manoj Kumar -
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 -
Extracting the Attributes values of an XML Element
Dear Forum Members
Please tell me any XML Function which is used to extract the Attribute value of an XML Element.
Given below
<BRKCD_STREDSWTINVIN_C Key="6708">
is an Element With some Key value.
I want to have that Key value.
Using Extract and Extractvalue I am not able to get the Attribute value.
Is there any way..
Regards
Madhu KYour xml is not really complete ;), but this should get you started:
michaels> with t as
(select xmltype('<BRKCD_STREDSWTINVIN_C Key="6708"></BRKCD_STREDSWTINVIN_C>') xml from dual)
select d.xml, d.xml.extract('//BRKCD_STREDSWTINVIN_C/@Key') key
from t d
XML KEY
<BRKCD_STREDSWTINVIN_C Key="6708"></BRKCD_STREDSWTINVIN_C> 6708 -
XmlObject - set value of element with a particular attribute
Hi,
In a xmlObject I try to set the value of xml element with a particular attribute but it doesn't work
//get value of element with a particular attribute
var myValue = xmlObject.ELEMENTS.ELEMENT.(@category == "myCategory"))// works fine
//set value of element with a particular attribute
var myValue = "foo"
xmlObject.ELEMENTS.ELEMENT.(@category == "myCategory"))= myValue // doesn't work
Thanks for your help
RegardsHi Dirk,
For example :
var xmlObject = new XML ( "<rootElement> <elements> <element category='foo1'>value1</element> <element category='foo2'>value2</element> <element category='foo3'>value3</element> </elements></rootElement>");
myValue = xmlObject.elements.element.(@category == "foo1");
$.writeln(myValue)// return value1
// Now I want modify value1 to value99 like this
xmlObject.elements.element.(@category == "foo1")= "value99"; //doesn't work
I hope I was clear in my explanation ;-)
Regards -
Changing Element Attribute Values
I spent far to long trying to figure out how to change an element attribute value without the FDK's SetAttributes function, so I thought I'd spare someone else the time.
Basically, you still get the attributes using the GetAttributes() function, but now you just set the beg.child.Attributes property to the updated attribute value.
//starting with a selected element
elemSelect=app.ActiveDoc.ElementSelection
//get the current attributes
var childattributes =elemSelect.beg.child.GetAttributes()
//find the attribute and value you want to change, and change it to a new value.
childattributes[0].values[0] = "New_Value"
//now assign the edited attributes to the selected element.
elemSelect.beg.child.Attributes=childattributes
Depending on how you selected the element, I assume you could do the above with beg.parent as well, but it wasn't something I needed to consider.
~ChristenThanks for this--you've likely saved me a headache.
While I hadn't hit this yet, it does apply to several of the projects on my to-do list. Based on the info in the OMV, I would have expected to be able to simply use a statement like myElement.Attributes[i].value[i] = "New_Value" which, as I'm sure you discovered, has no apparent effect at all.
The other thing I noticed in my quick testing is that defining your attributes variable by using the method (x = myElement.GetAttributes()) or by referenceing the Attributes property (x = myElement.Attributes) seem to be functionally equivalent. -
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,
MayHere 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")); -
Not getting attribute values in IPC routines Scenerio R/3 B2B using AP 7.0
Hi,
Our Scenerio is using ISA R/3 B2B using AP 7.0. I have developed IPC routines but when i debug my routines in SM53 I notice that I'm not getting any attribute value except for VKORG.
I'm pasting the code below. Please help me if I have to implement some BADI or do something more to get the attribute values.
I have defined the attributes properly in Routine assignment in tcode /n/sapcnd/ueass
userexitlogger.writeLogDebug("*requirment 901*" + "Plant = "plant"||ANZ_MONATE ="+ item.getAttributeValue(ANZ_MONATE_STR).toString()"||ANZ_JAHRE="item.getAttributeValue(ANZ_JAHRE_STR).toString()"||MATKL="item.getAttributeValue(MATKL_STR).toString()"||PSTYV="item.getAttributeValue(PSTYV_STR).toString()"||VKORG="item.getAttributeValue(VKORG_STR)"||PRSFD="item.getAttributeValue(PRSFD_STR)"||MVGR2="item.getAttributeValue(MVGR2_STR).toString()"||PRSDT="item.getAttributeValue(PRSDT_STR).toString()"||AUDAT="item.getAttributeValue(AUDAT_STR).toString());
I would reward points for help
Many Thanks n regards,
DipenderI would like to go through each Value of the xml file and give each Value a name
e.g. from the xml file <VentCount Value=1> Retreive the value above and giving it the name VentCount. Then I would beable to use the name vent count as follows:
setVentCount() //My own method can use as follows: setVentCount(VentCount); I would like to do his for ever value, each value with a specific name -
Not getting all the attributes value from Trusted Recon in eventhandler
Hi,
I am not getting the values of all the attributes in hashmap from Trusted recon in eventhandler.
Following is the hashmap value I am getting :
Parameter Hashmap value is {re_key=1869, Email=[email protected], Role=Full-Time, act_key=22, User Login=TUser43, Xellerate Type=End-User, Last Name=User43, First Name=Test}
Please let me know how to get all the attributes value in eventhandler. I need to take some decisions based on these attributes.
ThanksYou should be getting all the values in the recon event.
To get the current user states for all the records in the bulk event use this:
Identity[] currentUserStates = (Identity[]) eventDataHashMap.get("CURRENT_USER");
Now when you are looping through your bulkParametersp[], you can use the same get from the currentUserStates:
Identity currentUser = null;
currentUser = currentUserStates[counter];
Now if the attribute is not in your hashmap, you can use:
currentUserState.getAttributes().get(attribute)
-Kevini -
How to get attribute value from standard page ?
Hi,
How to get attribute value from standard page ?
String str = (String)vo.getCurrentRow().getAttrbute("RunId");
But this value is returning a null value ....
Can anyone help me to get this attribute value which is actually having a actual value .getCurrentRow() would always return null if no setCurrentRow() is used.
Please check the page design and understand how many rows of VO are there. You can also use the following to get the row:
vo.reset();
vo.next();
Regards
Sumit
Maybe you are looking for
-
My iPhone 5 keeps pausing music using 30 pin to lightening adapter in my car
I have a Blitzsafe iPhone adapter in my car and recently upgraded to the iPhone 5. I purchased the wired 30 pin to lightening adapter and the music will start off playing fine but it randomly stops the music every 30 seconds or so, doesn't happen al
-
When I get a text while the phone is locked it doesn't make the designated alert sound, but it does if the phone is unlocked and in use.
-
How to count number of occurence of a particular charchter
Hi All, Anybody there who can help me in counting the no. of occurence of a particular char in a string, with the help of a select query !!! For example : there is a string 'RAJENDRA'. I want the select query to print 2 in this case without using a p
-
Incredibly Frustrated w iPhoto (simple copying)
Since 2005, I have nearly 35,000 images and video footage that I would like to COPY onto an[other] external drive. When I started filling up my iMac, I purchased an external drive for Time Machine purposes, and also created a folder that iPhoto would
-
I have just bought a pavillion 500-242ea with an amd radeon hd7560d graphics . There is an hdmi port which I have connected to my tv but the tv says there is no signal. I have no trouble connecting a differnt desktop and my laptop to the tv. Could an