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 7173387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:48:49+00:00 2026-05-28T15:48:49+00:00

I am parsing some XML using Nokogiri and XPath. When I do this: doc.xpath(‘//Order/child::node()’).each

  • 0

I am parsing some XML using Nokogiri and XPath. When I do this:

doc.xpath('//Order/child::node()').each do |node|
  puts node.name
end

It prints out all the nodes, but also in between names, it prints out ‘text’. I think I know why:

In my xml, there’s spaces between nodes like this : "<a1>hi</a1> \n <a2>bye</a2>"

Is there a way I can tell it to ignore stuff between nodes?

  • 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-28T15:48:51+00:00Added an answer on May 28, 2026 at 3:48 pm

    Use:

    //Order/node()[not(self::text()[not(normalize-space())])]
    

    this selects all children nodes of any Order element, except the ones that are text nodes consisting entirely of white-space.

    XSLT – based verification:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
    
     <xsl:template match="/*">
         <xsl:variable name="vSel1" select="//Order/node()"/>
         <xsl:variable name="vSel2" select=
         "//Order/node()[not(self::text()[not(normalize-space())])]"/>
    
         <xsl:for-each select="$vSel1">
           <xsl:value-of select="concat('&#xA;',position(), ': ')"/>
           <xsl:copy-of select="."/>
           <xsl:text>&#xA;</xsl:text>
         </xsl:for-each>
    ================
         <xsl:for-each select="$vSel2">
           <xsl:value-of select="concat('&#xA;',position(), ': ')"/>
           <xsl:copy-of select="."/>
           <xsl:text>&#xA;</xsl:text>
         </xsl:for-each>
     </xsl:template>
    </xsl:stylesheet>
    

    when this transformation is applied on the following XML document:

    <t>
     <Order>
      <a/>
      <b>xxx</b>
      <c/>
     </Order>
     <Order>
      <d/>
      <e>xxx</e>
      <f/>
     </Order>
    </t>
    

    the two XPath expressions are evaluated and the nodes of two corresponding sets of selected nodes are output, each preceded by its position number:

    1: 
    
    
    2: <a/>
    
    3: 
    
    
    4: <b>xxx</b>
    
    5: 
    
    
    6: <c/>
    
    7: 
    
    
    8: 
    
    
    9: <d/>
    
    10: 
    
    
    11: <e>xxx</e>
    
    12: 
    
    
    13: <f/>
    
    14: 
    
    
    ================
    
    1: <a/>
    
    2: <b>xxx</b>
    
    3: <c/>
    
    4: <d/>
    
    5: <e>xxx</e>
    
    6: <f/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having some problems parsing this piece of XML using SimpleXML. There is
I am having trouble parsing some returned XML using this command: XML::Parser.string(xml_string).parse Here is
I am parsing some XML something like this: <root> <some_gunk/> <dupe_node> ... stuff I
I am parsing some XML from an RSS feed (using NSXMLParser) for a blog
I'm having issues parsing some XML using DefaultHandler2. My XML takes the following form:
I am parsing some xml entries using the xmltextreader and looking for the elements
I am using SaxParser for parsing a XML which contains some image url which
Can I get some help parsing the my_cool_id from the following xml using XDocument?
I am displaying images from an URL using XML parsing and some images are
I'm having some trouble parsing malformed XML in PHP. In particular I'm querying a

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.