Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Please see It is uncool to update a node in a way that renders replies confusing or meaningless and mark your updates as such. It's the part starting with:

Here is my tried implementation. what changes do I need to make to get the desired output?

Your example is not complete (SSCCE) because it does not compile, does not show any input data, or most importantly which XML/HTML module you are using. My best guess at the moment based on the method names is XML::DOM. If that is the case, then the minimum change needed to your code to get it to work* is to change if($kids->item($k)->toString() =~ /<alt>/i) to if ( $kids->item($k)->getNodeType==ELEMENT_NODE && $kids->item($k)->getTagName eq 'alt' ).

* Update: "work" in this case meaning, to actually have an effect on the single example you provided. This doesn't address the question of only removing empty tags, but your approach of iterating over the list of children would work there as well, inspecting each one to see whether you consider it "content" or not, similar to what I do in my Mojo example.

Update 2: You edited the root node again. As I said above, don't do that, post a new question.


In reply to Re: Replace empty alt tag on <img> tag (updated) by haukex
in thread Replace empty alt tag on <img> tag by vlearner

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-20 07:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found