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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:43:00+00:00 2026-05-24T04:43:00+00:00

So I’m trying to write a function that does the following: I have about

  • 0

So I’m trying to write a function that does the following: I have about 20 or so XML files (someday I will have over a hundred) and in the header of each file is the name of a person who was a peer review editor <editor role="PeerReviewEditor">John Doe</editor>. I want to run through the directory where these files are stored and capture the name of the Peer-Review-Editor for that file. I want to end up with an variable $reviewEditorNames that contains all of the different names. (I will then use this to display a list of editors, etc.)

Here’s what I’ve got so far. I’m worried about the last part. I feel like the attempt to turn $editorReviewName into $editorReviewNames is not going to combine the individuals for each file, but an array found within a given file (even if there is only one name in a given file, and thus it is an array of 1)

I’m grateful for your help.

function editorlist()
{
    $filename = readDirectory('../editedtranscriptions');
    foreach($filename as $file)
    {
        $xmldoc = simplexml_load_file("../editedtranscriptions/$file");
        $xmldoc->registerXPathNamespace("tei", "http://www.tei-c.org/ns/1.0");
        $reviewEditorName = $xmldoc->xpath("//tei:editor[@role='PeerReviewEditor']");

        return $reviewEditorNames[] = $reviewEditorName;
    }


}
  • 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-05-24T04:43:01+00:00Added an answer on May 24, 2026 at 4:43 am

    I would put things more apart, that helps as well when you need to change your code later on.

    Next to that, you need to check the return of the xpath, most likely you want to process only the first match (is there one editor per file?) and you want to return it as string.

    If you put things into functions of it’s own it’s more easy to make a function to only do one thing and so it’s easier to debug and improve things. E.g. you can first test if a editorFromFile function does what it should and then run it on multiple files:

    /**
     * get PeerReviewEditor from file
     *
     * @param string $file
     * @return string
     */
    function editorFromFile($file)
    {
        $xmldoc = simplexml_load_file($file);
        $xmldoc->registerXPathNamespace("tei", "http://www.tei-c.org/ns/1.0");
    
        $node = $xmldoc->xpath("//tei:editor[@role='PeerReviewEditor'][1]");
        return (string) $node[0];
    }
    
    /**
     * get editors from a path
     *
     * @param string $path
     * @return array
     */
    function editorlist($path)
    {
        $editors = array();
        $files = glob(sprintf('%s/*.xml', $path), GLOB_NOSORT);
        foreach($files as $file)
        {
            $editors[] = editorFromFile($file);
        }
        return $editors;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.