Can't get attribute out of XML

22 views
Skip to first unread message

leam hall

unread,
Aug 9, 2016, 3:44:15 PM8/9/16
to nokogiri-talk
I'm trying to pull a particular attribute "[@severity]" from a Rule. 

To get the title, I use:   
    vuln['title']           = group.xpath('Rule/title').text

However, this doesn't get the attribute:
    vuln['severity']        = group.xpath("Rule[@severity]").text

Snippet of the XML. In this case I want vuln['severity'] to have the string "medium". Right now it's getting several of the child fields.

    #(Element:0x3f89f9a80120 {
      name = "Rule",
      attributes = [
        #(Attr:0x3f89f9a7d830 {
          name = "id",
          value = "SV-68627r3_rule"
          }),
        #(Attr:0x3f89f9a7d7e0 {
          name = "severity",
          value = "medium"
          }),
        #(Attr:0x3f89f9a7d7cc {
          name = "weight",
          value = "10.0"
          })],
      children = [
        #(Text "\n"),
        #(Element:0x3f89f9a6edbc {
          name = "version",
          children = [
            #(Text "RHEL-06-000163")]
          }),
        #(Text "\n"),

Mike Dalessio

unread,
Aug 15, 2016, 12:30:40 AM8/15/16
to nokogiri-talk
Please provide the XML you're parsing, and what your expected result is.


--
You received this message because you are subscribed to the Google Groups "nokogiri-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nokogiri-talk+unsubscribe@googlegroups.com.
To post to this group, send email to nokogi...@googlegroups.com.
Visit this group at https://groups.google.com/group/nokogiri-talk.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages