Perl XPath : How to get the value of the attribute?

  • Permalink
  • submit to reddit
  • Email
  • Follow


Hi,

I have the following XML :

<checkIn bug="1111111">
   <regression>
   </regression>
</checkIn>

How do i get the value "1111111" for bug ?

I am able to get everything under <checkIn> using

my $bug = $xPath->find("/checkIn[\@bug]");

TIA
--

Abhinav
0
Reply Abhinav 7/29/2004 12:32:30 PM

See related articles to this posting



Abhinav wrote:


> I have the following XML :
> 
> <checkIn bug="1111111">
>   <regression>
>   </regression>
> </checkIn>
> 
> How do i get the value "1111111" for bug ?
> 
> I am able to get everything under <checkIn> using
> 
> my $bug = $xPath->find("/checkIn[\@bug]");

I don't use Perl, but the XPath should be
   /checkIn/@bug

-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/

0
Reply Martin 7/29/2004 12:52:46 PM

Martin Honnen wrote:
> 
> Abhinav wrote:
> 
> 
> 
>>I have the following XML :
>>
>><checkIn bug="1111111">
>>  <regression>
>>  </regression>
>></checkIn>
>>
>>How do i get the value "1111111" for bug ?
>>
>>I am able to get everything under <checkIn> using
>>
>>my $bug = $xPath->find("/checkIn[\@bug]");
> 
> 
> I don't use Perl, but the XPath should be
>    /checkIn/@bug
> 

Thanks. That Worked !

I guess the extra / allows me to fetch only the node containing the 
attribute ?

Any docs (apart from the CPAN XPath docs) which detail these concepts more 
clearly ?

TIA

--

Abhinav
0
Reply Abhinav 7/29/2004 1:06:53 PM

Abhinav wrote:
> 
> Any docs (apart from the CPAN XPath docs) which detail these concepts 
> more clearly ?

  Google is your friend :

  http://www.w3schools.com/xpath/default.asp

  And the official W3C reccomendation :

  http://www.w3.org/TR/xpath

  Franck,e-

> 
> TIA
> 
> -- 
> 
> Abhinav
0
Reply Franck 7/29/2004 1:07:09 PM


Abhinav wrote:

> Martin Honnen wrote:
> 
>>
>> Abhinav wrote:
>>
>>
>>
>>> I have the following XML :
>>>
>>> <checkIn bug="1111111">
>>>  <regression>
>>>  </regression>
>>> </checkIn>
>>>
>>> How do i get the value "1111111" for bug ?
>>>
>>> I am able to get everything under <checkIn> using
>>>
>>> my $bug = $xPath->find("/checkIn[\@bug]");
>>
>>
>>
>> I don't use Perl, but the XPath should be
>>    /checkIn/@bug
>>
> 
> I guess the extra / allows me to fetch only the node containing the 
> attribute ?

No, it selects the attribute node itself,
   /checkIn
selects the <checkIn> root element,
   /checkIn/@*
selects all its attribute nodes, and
   /checkIn/@bug
selects the attribute with name bug

> Any docs (apart from the CPAN XPath docs) which detail these concepts 
> more clearly ?

There is the XPath 1.0 specification:
   http://www.w3.org/TR/xpath
And there are tutorials, see
   http://www.w3schools.com/xpath/default.asp
for instance.

-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/

0
Reply Martin 7/29/2004 1:13:27 PM
comp.lang.perl.misc 32791 articles. 7 followers. Post

4 Replies
477 Views

Similar Articles

[PageSpeed] 57


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

picking value of one attribute based on a child elements attribute? XPath?
Hi, I'm relatively new to xml. I want to have a xml element of the form: <!ELEMENT CAR (MAKE, COMPANY)> <!ATTLIST CAR TYPE PCDATA PRICE PCADATA> <!ELEMENT COMPANY (HQ, COMPANY_TYPE)> Is there a way such that CAR/TYPE has the same value as CAR/COMPANY/COMPANY_TYPE either using DTD or a schema . For example, whenever, CAR/COMPANY/COMPANY_TYPE = "PRICEY" then, CAR/TYPE = "PRICEY" I think something like XPath is needed but am not sure how to go about getting this. Can I use XPath inside XML ele...

Problem selecting a node with XPATH if attribute value contains backslashes
VB6, MSXML 3.2 installed: Q1. I am having a problem selecting nodes with XPATH expressions when an attribute values contain backslashes (\\) in as part of its value: For example the following statement fails to find a node (even though one exists in the XML) if the value of the LDAPServerURL attribute is \\LocalServer but works if the value is "LocalServer". Set xmlElement = _ xmlConfigFile.documentElement.selectSingleNode("Facility[@LDAPServerURL='" & <SomeValue> & "']") I assumed that anything inside the '' was treated as a li...

How can I get attribute values to not get converted from &apos; to ' or &amp; to & or &lt; to > ?
Hi, my mind is going crazy. I have tried everything I can think of to no avail. I have tried Disable Output Escaping. I tried to think of a way of enclosing the attribute data in a CDATA element. That did not parse. Here is my question: How can I get attribute values to not get converted from &apos; to ' or &amp; to & or &lt; to > ? It seems like if I take the xsl:value-of an attribute and then output that value into another xml it get's converted. The problem is I am importing this stuff into a DB and I need to keep all those &apos; and other escapings.....

trying to get an attribute value
Hello, I'm trying the following code: function MoveTeam(id){ This works-gets the value of the element var x=document.getElementById(id).innerHTML; This doesnt get the value of the alpha attribute of the same element. I get a js error. var q=document.getElementByID(id).attribute('alpha') alert (q) Thanks Mike Mike wrote: > Hello, > I'm trying the following code: > function MoveTeam(id){ > This works-gets the value of the element > var x=document.getElementById(id).innerHTML; > This doesnt get the value of the alpha attribute of the same element. > I get a ...

getting the value of an attribute from pdb
Hi how can I "using pdb" get a value of an attribute?, read the docs and played around with pdb 'p' for no avail. thanks class main: def __init__(self, master): self.master = master self.master.title('parent') self.master.geometry('200x150+300+225') .... root = Tk() **************** **************** ignore the following if you are not interested on how I tried **************** **************** (Pdb) n > /home/fred/python/practic/window_08.py(12)__init__() -> self.master.geometry('200x150+300+225') (Pdb) p root.title <bound me...

How to get max value with Xpath
given: <links> <l><a>1</a><n>Building</n></l> <l><a>4</a><n>Community</n></l> <l><a>2</a><n>Comedy</n></l> <l><a>3</a><n>Computer</n></l> </links> What is an Xpath statement to find the maximum value in the "a" element node. It would be 4. I have searched and tried many examples with no luck. It must be simple? I could easily parse into an array and use an array's max function but would like to learn the xpat...

Get root attribute values
Hi, <root some_attr="edit"> <a/><a/> <root> How do I access the value of some_attr when processing <a/> ? Sort of like if I had <root> <some_attr>edit</some_attr> </root> Then I could count on fetching some_attr as /root/some_attr . But here I want to use an attribute not an element as in the sort of like example. Thanks. Hello, GIMME! You wrote on 8 Apr 2004 17:56:55 -0700: G> <root some_attr="edit"> G> <a/><a/> G> <root> G> How do I access the value of some_attr when pr...

Getting attribute value from a xml
Hi there, Goal: To be able to read one special value from a given XML which looks like that: <adminTools> <admins> <admin steamID="123789" permission_level="0"/> </admins> <moderators> <moderator steamID="123789" permission_level="1"/> </moderators> <permissions> <permission cmd="help" permission_level="0"/> <permission cmd="shutdown" permission_level="0"/> <permission cmd=&quo...

get values from the textbox in perl TK
Hai I want to get the values from the text box when u typed it in the run time. how to get the values and how to put the same in the another same text. regards, Jayashree maami wrote: > Hai > I want to get the values from the text box when u typed it in the > run time. > how to get the values and how to put the same in the another same text. The get() and insert() methods are described in the Tk::Text pods. --Ala On Fri, 14 May 2004 04:53:45 -0400, maami wrote: > I want to get the values from the text box when u typed it in the > run time. > how ...

When do elements get their style attribute values?
There are some elements in one of my app's pages whose height values I'd like to get as soon as possible, since I want to use the values to calculate and set heights of other elements. And I'd like to be able to either get the element's natural height or one I set using CSS. So, I'm doing something like [1]: h = document.defaultView.getComputedStyle(e,null).getPropertyValue("height"); where e is a pointer to my element. But I find that if I do this right at the start of the onload function, I get back a zero value, whereas if I do it a bit later (e.g. aft...

How to get cell value excel in perl
Hi good people: I need to get value of the cell so I can split by : and do some calculation,the format of numbers is like 12:03:20. Is there any way that I can get the value of the cell in perl...thanks in advance.. my $workbook = Spreadsheet::WriteExcel->new($out); my $worksheet = $workbook->add_worksheet("Result"); my $t1 = xl_rowcol_to_cell(2, 4); # E2 my $t2 = xl_rowcol_to_cell(2, 5); # F2 my ($t1_h, $t1_min, $t1_sec) = split (/\:/, $t1); my ($t2_h, $t2_min, $t2_sec) = split (/\:/, $t1); my $delta= $worksheet->write('G2', '=$t2_h - t1_h...

get attribute value from an XML tag
hello, how do i get the attribute "href" value using the following script ? <news> <story> <headline href=http://www.bibo.com > Godzilla Attacks LA! </headline> <description>Eq......... --------------------------------------- <?php $xml_file = "news.xml"; $xml_headline_key = "*NEWS*STORY*HEADLINE"; $xml_description_key = "*NEWS*STORY*DESCRIPTION"; $story_array = array(); $counter = 0; class xml_story{ var $headline, $description; } function startTag($parser, $data){ global $current_tag; ...

get list item by attribute value
Dear ALL, How can I do this best in XSLT2.0: Imagine I have a value from element/@attribute which represents an integer. With this integer I would like to choose a value from a list like this ('red', 'blue' , 'green' ) The list is pre-defined and stored in some global variable. How to acces it without long xsl:choose / when or if statements ? And what about there is no value returned from element/@attribute ? (In that case I would like to get a default value e.g. 'white' ) I guess there might be a nice function in xslt2, but I did not find one yet. Thank...

Newbie XPath attribute value question
Hello, I have XML-documents which are quite attribute-heavy and would like to search all attribute values for match with a certain string, no matter in what element or attribute they are found. What would the syntax be? Thanks in advance, -Nik * Nik wrote in comp.text.xml: >I have XML-documents which are quite attribute-heavy and would like >to search all attribute values for match with a certain string, no >matter in what element or attribute they are found. What would the >syntax be? //@*[. = 'text-you-are-looking-for'] Or instead of using = e.g. contains(...) dep...

Get attribute value by its string name
Hi there, In an XSLT stylesheet, I need to get a value of an attribute. The problem is that I need to generate the name of the attribute on the fly. Is it possible to get the value of an attribute knowing its string represented name? E.g. <xsl:attribute name="name"> <xsl:value-of select="concat($FieldPrefix, 'Name')"/> </xsl:attribute> The result is the concatenated string, e.g. <pwm_regardingrulesetid name="MyGivenPrefixName" ... However, MyGivenPrefixName is an attribute name in the source XML...

Get the values of all attributes/arguments of a widget
Hi, I am facing a peculiar problem. I am trying to display a string containing a newline character in a XmText widget. The input string is: "test \\n test1". Ideally I would like to have it displayed exactly as above(i.e, with two backslashes). In our application, it is displayed as "test \ test1" i.e, the first backslash is considered an independent character and characters "\n" are interpreted as newline character. I want it to be interpreted as simple characters. In my test application, it is displayed as "test \n test1" i.e, t...

How to get the value of an attribute in an XML node?
Hello, This is the url http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=gene&retmax=10000&term=cmyc of an xml file that I am trying to read and get the values of the <IdList> node in the - <IdList> <Id>30686</Id> <Id>4609</Id> <Id>17869</Id> <Id>5728</Id> <Id>6598</Id> <Id>9111</Id> </IdList> Here is the program that I am trying to read the values of the Id in the XML file ******************************program**************************** public cl...

DII: how to set and get attribute values.
To all: I defined an attribute in my IDL file: interface inventory{ attribute string Name; } ...

Changing the title and getting attribute values
Two questions: 1. How do I set the title of a document using CSS (preferred) or XSL (if that's how it has to be done) 2. How can I get an attribute value? For example, if I have the tags <tag attr="1">...<tag attr="498">, how can I use the value of attr? I'm assuming both of these are possible, which may be an overlarge XXXXXXXXL assumption, but I hope not. Max meinte: > Two questions: > > 1. How do I set the title of a document using CSS You can't. CSS is not about content. > 2. How can I get an attribute value?...

Get root attribute values question 2
If I have <root> <a some_attr="AAA"/> <b><c/></b> <b><c/></b> <b><c/></b> <b><c><d/></c><b> <root> What expression will fetch the value of AAA when processing elements c ? Is there an expression that works for both elements c and d ? Thanks. "GIMME" <gimme_this_gimme_that@yahoo.com> wrote in message news:3f12b4fb.0404081703.39989dd0@posting.google.com... > If I have > > <root> > <a some_attr="AAA"/> > <b><c/><...

get perl's return value
Hi, I am not sure if I should post this question in newsgroup for Java or Perl. If I want to call a Perl script in Java, but I want to get the return value from that Perl script, how can I do that? Right now what I am doing is just using Runtime.getRuntime.exec("perl script.pl"), but oviously I can't get the return value from that perl script. Thanks in advance. Wilson Chew On Tue, 27 Jul 2004 16:32:14 -0700, "Wilson Chew" <wchew@qualcomm.com> wrote: >Hi, > >I am not sure if I should post this question in newsgroup for Java or Perl. > >If I ...

Getting Custom Attribute Value from Table Row
I can't seem to get the value associated with an attribute I created on a table row called "BackColor". I can get the length without issue, but whenever I try the value I get nothing. Thanks in advance, Sean <-- Begin Script --> var lastColorUsed; function fnChangeBackColor(row, highlight) { if (highlight) { lastColorUsed = row.style.backgroundColor; row.style.backgroundColor = '#dcdfff'; } else { alert(row.BackColor.length); //this returns the value '7' row.style.backgroundColor = row.BackColor.value; } } <-- End Script --> <-- Begi...

Xpath selecting specific attributes and concatinating their values.
I have a the following xml node. <doc tag1="a" tag2="b" tag3="c" docTag1="d" docTag2="e"/> I would like to output "abc" I have the following XPATH2.0 so far //doc/@*[name()[starts-with(.,'tag')]] which returns a node list. Is there a better way of concatinating these? thanks in advance for any advice Sharat Koya wrote: > I have a the following xml node. > > <doc tag1="a" tag2="b" tag3="c" docTag1="d" docTag2="e"/> See <http://groups.google.co...

Getting default value of an attribute from the DTD file
Please, excuse me if the question is a basic one but I have not found any hint neither on XML4C samples, nor on Apache site. I'm using XML4C. I'm parsing an xml file and I'm getting to an attribute which is not explicitly specified in the xml file. The parser brings me its default value specified in DTD (if any) as the attribute's value. The question is: How do I get the default value if the attribute explicitly appears in the xml file with some value? Any help will be greatly appreciated. TIA. Alexander ...