I'm using XML::Simple to try and check the elements of an xhtml file. I eventually want a script to find elements that need an id, but don't have an id.

here's the perl, edited for brevity

use XML::Simple; use strict; my $config = XMLin('some.xhtml'); processhash($config,'$config'); sub processhash() { my ($href, $path, @junk) = @_; my %configr = %$href; foreach my $k (keys %configr) { print qq|$path :: $k = $configr{$k}\n|; if ($configr{$k} =~ m/HASH/i) //if it is another hash, iterate + through that hash also { processhash($configr{$k},qq|$path -> {'$k'}|); } } }
This works pretty good, it produces an output like this
$config -> {'hx:scriptCollector'} -> {'f:loadBundle'} -> {'bundle_id'} + :: basename = somebasename
for this xml element
<f:loadBundle id="bundle_id" basename="somebasename" var="lbls" />
if the element has children the script tells me it's a hash
$config -> {'hx:scriptCollector'} -> {'h:form'} :: h:panelGrid = HASH( +0x1e54150)
then process that hash, here's the next few lines of output
$config -> {'hx:scriptCollector'} -> {'h:form'} -> {'h:panelGrid'} -> +{'hruleDots1_panel_id'} :: width = 100% $config -> {'hx:scriptCollector'} -> {'h:form'} -> {'h:panelGrid'} -> +{'hruleDots1_panel_id'} :: columnClasses = hruleDots $config -> {'hx:scriptCollector'} -> {'h:form'} -> {'h:panelGrid'} -> +{'hruleDots1_panel_id'} :: cellspacing = 0

All in all, pretty cool. BUT...the whole point is that I'm going try and find elements that are supposed to have ids but do not.

I will add to the script to check and see if it needs an id property, but even when I do it will fail. It's the strangest thing, sometimes the value of the ID is a child of the element.

For example this element
<h:outputText styleClass="required" value="*" id="AdjustCCDetails_R +easonCode_table_required_id">
produces this from the script
{'h:outputText'} :: AdjustCCDetails_ReasonCode_table_required_id = HAS +H(0x1e5400c) {'h:outputText'} -> {'AdjustCCDetails_ReasonCode_table_required_id'} : +: value = * {'h:outputText'} -> {'AdjustCCDetails_ReasonCode_table_required_id'} : +: styleClass = required
the id propery of the element is a child hash of the element that holds the other properties of the element.

here's an example of what I expected XML

<h:outputText id="AdjustCCDetails_Comment_table_id" styleClass="label" + value="#{somevalue}">
script output
{'h:panelGrid'} :: h:outputText = HASH(0x1e16050) {'h:panelGrid'} -> {'h:outputText'} :: value = #{somevalue} {'h:panelGrid'} -> {'h:outputText'} :: id = AdjustCCDetails_Comment_ta +ble_id {'h:panelGrid'} -> {'h:outputText'} :: styleClass = label
That output has an id that I can test for, the previous output does not...even though it has a valid id.

So my questions are, Do I not understand how all this works? If this is the expected behaviour, how can I test for id properties? and Is there a better way to find all the missing ids from an xhtml file?


In reply to XML::Simple finding id property problem by JohnEl

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.