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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:19:27+00:00 2026-06-10T00:19:27+00:00

This should be easy for a Javascript expert . For those who don’t know

  • 0

This should be easy for a Javascript expert.

For those who don’t know what schema is ( http://schema.org ), it’s a new way for Search Engines to read content on a webpage. It works by tagging relevant data with specific tags.

For those who do know what it is, here is a chrome extension (Schema Explorer) that makes it easy to inspect what your data looks like on your page. See the example.

NOW: There is a tiny issue with the extension where by is does not skip/ignore empty nested elements. Here are two examples: The first works perfectly but, the second bombs because of the empty <div> tag:

First example works:

<div itemscope="" itemtype="http://schema.org/Movie">
   <h1 itemprop="name">Avatar</h1>
   <div itemprop="director" itemscope="" itemtype="http://schema.org/Person">
      Director: <span itemprop="name">James Cameron</span> (born <span itemprop="birthDate">August 16, 1954</span>)
   </div>
   <span itemprop="genre">Science fiction</span>
   <a href="http://pierreloicdoulcet.fr/movies/avatar-theatrical-trailer.html" itemprop="trailer">Trailer</a>
</div>

Seconds example gives issues:

<div itemscope="" itemtype="http://schema.org/Movie">
   <div>
     <h1 itemprop="name">Avatar</h1>
     <div itemprop="director" itemscope="" itemtype="http://schema.org/Person">
         Director: <span itemprop="name">James Cameron</span> (born <span itemprop="birthDate">August 16, 1954</span>)
     </div>
     <span itemprop="genre">Science fiction</span>
     <a href="http://pierreloicdoulcet.fr/movies/avatar-theatrical-trailer.html" itemprop="trailer">Trailer</a>
   </div>
</div>

I had a look at the extension and it’s actually very well put together with one javascript file doing most of the work. Here is the code that does the looping, however it needs to be able to skip empty nested elements and perhaps be a little bit more robust in general:

    var __explore = function(node, parentData)
    {
        if (parentData === null || parentData === undefined)
        {
            parentData = __dataTree;
        }
        if (node.getAttribute)
        {
            var isItemScope = node.getAttribute('itemscope');
            var hasItemProp = node.getAttribute('itemprop');
            var itemtype = node.getAttribute('itemtype');


            var childs = node.childNodes;

            var i = 0;

            var tmp = new Array();

            while (i < childs.length)
            {
                if (isItemScope !== null)
                    __explore(childs[i], tmp);
                else
                    __explore(childs[i], null);
                ++i;
            }

            if (isItemScope !== null)
            {
                parentData.push({name : 'scope', value : hasItemProp, type : itemtype, childs : [tmp], node : node});
            }
            else if (hasItemProp && parentData)
            {
                parentData.push({name : hasItemProp, value :  node.innerText});
            }
        }
    }

Here is the complete versions of the contentscript.js https://gist.github.com/3413475

Hopefully someone can help me with this. For the record I’ve contacted the author but he’s been preoccupied with more urgent matters.

  • 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-06-10T00:19:29+00:00Added an answer on June 10, 2026 at 12:19 am

    I made it work as expected: http://jsfiddle.net/vyrvp/1/ but I must confess that this is a bit hackish. This code may need some more refactoring to make it work for all cases and make it readable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This should be easy, just curious. I know httpd is the HTTP daemon, just
This should be very easy but I don't know how to do it. I
This should be easy, but since I'm new to programming, specially in javascript, I
I know there should be an easy way to do this but I guess
This should be an easy question for anyone who has served a rails partial
This should be easy (at least no one else seems to be having a
This should be easy to find out but I can't seem to find it
It seems this should be easy but I'm having a lot of difficulty using
OK, I'm feeling like this should be easy but am obviously missing something fundamental
This should be quite easy, and I have done some research on this. I

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.