Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6778489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:16:19+00:00 2026-05-26T16:16:19+00:00

I have this XML: <record> <f id=27>John Smith</f> <f id=28/> </record> and parse it

  • 0

I have this XML:

<record>
    <f id="27">John Smith</f>
    <f id="28"/>
</record>

and parse it with Nokogiri this way:

# I get the record from the whole document
... 
fields = record.xpath("f")
for field in fields
    puts field.content
end

which returns this:

John Smith
\n 28 \n

This is incorrect. The second field tag does not have anything inside the tag, it should return an empty value. Right?

By the way, the same thing happens with LibXML.

This is the Actual code:

xml = Nokogiri::XML("<?xml version="1.0" ?><records><record><f id="27">John Smith</f><f id="38"/></record></records>")

records = xml.xpath("//record")
records.map{|record|
    fields = record.xpath("f")
    fields.to_enum(:each_with_index).collect{|field,index|
        [field.content, index]
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:16:20+00:00Added an answer on May 26, 2026 at 4:16 pm

    I’ll answer the question. The tag probably contains other tags in it that you might’ve missed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML document which looks something like this: <meadinkent> <record> <comp_div>MENSWEAR</comp_div> <sty_ret_type>ACCESSORIES</sty_ret_type>
I have this document where i want to get to the value in x_server_response/retrieve_resources_by_category_response/source_full_info/record/
I have some XML which contains records and sub records, like this: <data> <record
I have this xml from which I am trying to grab the value in
I have this XML document <xml> <word> <threeletter>rip</threeletter> <fourletter>Pier</fourletter> <fiveletter>Spire</fiveletter> <sixletter>Spider</sixletter> </word> <word> <threeletter>rip</threeletter>
I have this stored procedure, that reads data from xml and make some inserts
I have the following node I need to parse using XSLT 1.0 from xml
ok this is driving me crazy. I have been trying to parse a xml
I have this XML: <Record> <ID>123</ID> <Question>Question goes here...</Question> <Answer>Answer goes here...</Answer> <ExtentedAnswer>&lt;?xml version=1.0
I am writing an XML document in C#. I have something like this... string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.