in reply to Ordering meta tags with HTML::Element

Thanx for your input so far

I think I should clarify the the problem it's not browser, they don't care what order the meta data is or charset

The output is read by an automated process this is failing because it requires the meta tags to be name content eg

<meta name="Author" content="J K Rolling" /> <meta name="title" content="Harry Potter and the Philosopher's Stone" + />
This is a mok up of the problem the actual script is over 6000 lines so just not practical to upload here

Replies are listed 'Best First'.
Re^2: Ordering meta tag attributes with HTML::Element
by hippo (Archbishop) on Jun 15, 2016 at 08:29 UTC
    The output is read by an automated process this is failing because it requires the meta tags to be name content

    In that case you have a problem because this "automated process" is not accepting valid HTML and pretty much any of the pre-written modules you might use (HTML::Element included) will not care about attribute ordering as has been discussed by my fellow monks already.

    The real fix here is to change the "automated process" to avoid the insistence on attribute ordering. Failling that, I guess you will need to abandon HTML::Element and fall back on hand-rolling the HTML. Good luck.

      I have no control over the automated process The only solution I have come up with is to do this but not very elegant I was hopping someone would have a better idea
      for my $m (sort keys %meta) { my $m_el = HTML::Element->new('meta'); $m_el->attr('0name',$m); $m_el->attr('1content',$meta{$m}); $head->push_content($m_el); } my $out = $body->as_HTML('<>&',' ',{}); $out=~s/0name/name/g; $out=~s/1content/content/g; print $out;

        If you look at the source code of HTML::Element, you will find that it prefers to sort the attribute keys alphabetically. My approach would be to derive a class from HTML::Element which overrides the to_string method (or whatever) to output the attributes in a more explicit manner. I think something like this was already suggested to you.

        Your approach of hoping that the text will never contain 0name or 1content is also plausible, personally, I would rather look at using one of the template solutions to create text that absolutely must follow a specific format.

        Maybe that "automated process" doesn't process your data, because you misspelt the content of the "Content" attribute of the first "meta" element?
        At least if a lookup is involved, it may simply not find "J K Rolling".
      ...hand-rolling the HTML

      Hahaha.

      Yeah. Maybe he can hire some of the neighborhood kids to help him. They probably are looking for something to do this summer.

      (Thank you for adding some humour to my day.)

Re^2: Ordering meta tags with HTML::Element
by Cow1337killr (Monk) on Jun 21, 2016 at 19:12 UTC
    6,000 lines. I am new here. Can't you use pastebin?
      6,000 lines. I am new here. Can't you use pastebin?

      How would that help? No one reads 6000 lines. And it's off-site, probably getting lost over time. Not to mention confidentiality.

      Generally, it is much more helpful to post a short, self-contained example right here.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)