Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Why no response to Re^3: Extracting specific childnodes (xpath whitespace)?

If you're game, I'm game ; I'll play if you'll play;

Using the previous answer

$ xmllint.exe --shell madbee.xml / > / > cat //H4[ contains(.,'Include')] /..//LI ------- <LI> <LI_Label>1.</LI_Label> <LI_Title>Critera 1</LI_Title> </LI> ------- <LI> <LI_Label>2.</LI_Label> <LI_Title>Critera 2</LI_Title> </LI> ------- <LI> <LI_Label>3.</LI_Label> <LI_Title>Critera 3</LI_Title> </LI> ------- <LI> <LI_Label>4.</LI_Label> <LI_Title>Critera 3</LI_Title> </LI> / > / > / > cat //H4[ contains(.,'Include')] /..//LI_Title ------- <LI_Title>Critera 1</LI_Title> ------- <LI_Title>Critera 2</LI_Title> ------- <LI_Title>Critera 3</LI_Title> ------- <LI_Title>Critera 3</LI_Title> / > / > bye $

Debugging /diagnosing and fixing this latest typo-ed answer

$ xmllint.exe --shell madbee.xml / > / > cat //Article/Main/Sect/*[ ( name()="H3" or name()="H4" ) and cont +ains(.,"Include" ) ]//LI_Title / > / > whereis //Article/Main/Sect/*[ ( name()="H3" or name()="H4" ) and +contains(.,"Include" ) ]//LI_Title / > / > cat //Article/Main/Sect/*[ ( name()="H3" or name()="H4" ) and cont +ains(.,"Include" ) ] ------- <H4>Include</H4> / > / > whereis //Article/Main/Sect/*[ ( name()="H3" or name()="H4" ) and +contains(.,"Include" ) ] /Article/Main/Sect/H4 / > / > whereis //LI_Title /Article/Main/Sect/L/LI[1]/LI_Title /Article/Main/Sect/L/LI[2]/LI_Title /Article/Main/Sect/L/LI[3]/LI_Title /Article/Main/Sect/L/LI[4]/LI_Title / > / > / > cat //Article/Main/Sect/*[ ( name()="H3" or name()="H4" ) and cont +ains(.,"Include" ) ]/../LI_Title / > / > cat //Article/Main/Sect/*[ ( name()="H3" or name()="H4" ) and cont +ains(.,"Include" ) ]/..//LI_Title ------- <LI_Title>Critera 1</LI_Title> ------- <LI_Title>Critera 2</LI_Title> ------- <LI_Title>Critera 3</LI_Title> ------- <LI_Title>Critera 3</LI_Title> / > / > / > / > grep Include /Article/Main/Sect/H4 : tan 7 Include / > / > / > grep Critera /Article/Main/Sect/L/LI[1]/LI_Title : t-- 9 Critera 1 /Article/Main/Sect/L/LI[2]/LI_Title : t-- 9 Critera 2 /Article/Main/Sect/L/LI[3]/LI_Title : t-- 9 Critera 3 /Article/Main/Sect/L/LI[4]/LI_Title : t-- 9 Critera 3 / > / > / > bye $

Using the power of parens in xpath / parentheses in xpath

$ xmllint.exe --shell madbee.xml / > cat //Article/Main/Sect/H4 ------- <H4>Include</H4> / > / > / > cat ( //Article/Main/Sect/H3 | //Article/Main/Sect/H4 ) ------- <H4>Include</H4> / > / > / > cat ( //Article/Main/Sect/H3 | //Article/Main/Sect/H4 )[ contains( +.,'Include' ) ] ------- <H4>Include</H4> / > / > / > cat ( //Article/Main/Sect/H3 | //Article/Main/Sect/H4 )[ contains( +.,'Include' ) ]/..//LI_Title ------- <LI_Title>Critera 1</LI_Title> ------- <LI_Title>Critera 2</LI_Title> ------- <LI_Title>Critera 3</LI_Title> ------- <LI_Title>Critera 3</LI_Title> / > / > / > / > cat ( //Article/Main/Sect/H3 | //Article/Main/Sect/H4 )[ contains( +.,'Junk' ) ]/..//LI_Title / > / > / > / > bye $

You can even give node sets to xpath string functions like contains() so you don't have to go to parent(..) then find descendents(//)

$ xmllint.exe --shell madbee.xml / > / > / > whereis //Article/Main/Sect /Article/Main/Sect / > / > / > whereis //Article/Main/Sect[ ( H3 | H4 ) ] /Article/Main/Sect / > / > / > whereis //Article/Main/Sect[ contains( ( H3 | H4 ), 'Junk' ) ] / > / > whereis //Article/Main/Sect[ contains( ( H3 | H4 ), 'Include' ) ] /Article/Main/Sect / > / > whereis //Article/Main/Sect[ contains( ( H3 | H4 ), 'Include' ) ] +//LI_Title /Article/Main/Sect/L/LI[1]/LI_Title /Article/Main/Sect/L/LI[2]/LI_Title /Article/Main/Sect/L/LI[3]/LI_Title /Article/Main/Sect/L/LI[4]/LI_Title / > / > / > bye $

In reply to Re^3: Extracting specific childnodes (play xmllint --shell ) by Anonymous Monk
in thread Extracting specific childnodes by madbee

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (7)
    As of 2014-07-10 06:50 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (202 votes), past polls