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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:36:49+00:00 2026-05-17T01:36:49+00:00

I have an XML file structured like this <serieslist> <series sid=123> <title type=main>Series 123

  • 0

I have an XML file structured like this

<serieslist>
    <series sid="123">
        <title type="main">Series 123 Main Title</title>
        <title type="official">Series 123 Official Title</title>
        <title type="short">S 123</title>
    </series>
    <series sid="456">
        <title type="main">Series 456 Main Title</title>
        <title type="official">Series 456 Official Title</title>
        <title type="short">S 456</title>
    </series>
    /* +6000 more <series> nodes */
</serieslist>

I need to make an associative array that consists of the “sid” attributes and main series titles like this

array(
    123 => "Series 123 Main Title",
    456 => "Series 456 Main Title",
    //...
);

I tried using this xpath query //series/title[@type="main"] and I get the nodelist

$xml = DOMDocument::load('serieslist.xml');
$xpath = new DOMXPath($xml);
$titles = $xpath->query('//series/title[@type="main"]');
$series = array();
foreach($titles as $title) {
    $series[] = $title->nodeValue;
}

Results in

$series = array(
    0 => "Series 123 Main Title",
    1 => "Series 456 Main Title",
    //...
);

But I need parent’s “sid” attribute too. How could I do that in a non-resource-intensive way?

  • 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-17T01:36:49+00:00Added an answer on May 17, 2026 at 1:36 am

    Quite simple. Just reference the parent node to $title:

    foreach($titles as $title) {
        $id = $title->parentNode->getAttribute('sid');
        $series[$id] = $title->nodeValue;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file that's structured like this: <foo> <bar></bar> <bar></bar> ... </foo>
I have a xml file structured like <?xml version=1.0?> <library> <book id=1003> <title>Jquery MVC</title>
I have an xml file stored on my website that looks like this: <games>
I have an xml mapping file that looks something like this <colourMappings> <model name=modelX>
I have an xml file nodes structure like this <Employee> <EmpId></EmpId> <EmpName></EmpName> <Salary> <Basic></Basic>
I have an XML file that looks like this: <?xml version=1.0? encoding=UTF-8 standalone=no?> <dir
I have XML file (output of some application) like this: <data> <call function=get_user_data> <output>
I have a trouble with parsing an XML File called test.xml like this :
I have a xml file roughly like this: <batch> <header> <headerStuff /> </header> <contents>
I have a XML file template like this that comes from some IC chips,

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.