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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:15:22+00:00 2026-05-14T21:15:22+00:00

Here is an example bit from the xml file: <array> <dict> <key>Name</key> <string>Joe Smith</string>

  • 0

Here is an example bit from the xml file:

<array>
    <dict>
        <key>Name</key>
        <string>Joe Smith</string>
        <key>Type</key>
        <string>Profile</string>
        <key>Role</key>
        <string>User</string>
        <key>Some Number</key>
        <integer>1</integer>
        <key>Some Boolean</key>
        <true/>
    </dict>
</array>

I have two separate goals. The first is to extract an array from the dictnode that would look like:

[Name] => Joe Smith
[Type] => Profile
[Role] => User
[Some Number] => 1
[Some Boolean] => true

It’s not crucial that the boolean be included, so if that adds too much complexity, I’d rather just know how to deal with the others for now.

The second goal is to be able to select the value node (<string>, <integer>,etc) so that I can change the value. I know I would need to select it based on the text value of the preceding key element.

I think the following XPath should work:

//key[.=$keyname]/following-sibling[1]

But I’m not sure.

Basically, this whole system that Apple uses seems logical, but totally contrary to my understanding of how XML is supposed to work. If I ran the world, the original XML would look more like:

<dict type="array">
    <value key="Name" type="string">Joe Smith</value>
    <value key="Type" type="string">Profile</value>
    <value key="Role type="string">User</value>
    <value key="Some Number" type="integer">1</value>
    <value key="Some Boolean" type="boolean">true</value>
</dict>

But since it is fairly logical, I am wondering if I’m missing some obvious way of handling it.

  • 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-14T21:15:23+00:00Added an answer on May 14, 2026 at 9:15 pm

    That xpath selector looks okay for that purpose to me. You’d probably want to check the value of the sibling you retrieve, to see if it’s the tag you want to be changing (in the boolean case) or indeed the element’s value.

    In terms of extracting the data into an array, something along the lines of …

    $xml = new SimpleXMLElement($data);
    
    $output = array();
    $key = null;
    $value = null;
    foreach ($xml->dict->children() as $child) {
      if ($child->getName() == 'key') {
        $key = (string)$child;
      } elseif (!is_null($key)) {
        $childStr = (string)$child;
        $value = (empty($childStr) ? $child->getName() : $childStr);
      }
    
      if (!is_null($key) && !is_null($value)) {
        $output[$key] = $value;
    
        $key = null;
        $value = null;
      }
    }
    
    var_dump($output);
    

    … should do what you’re looking for from what I understand.

    James

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

Sidebar

Ask A Question

Stats

  • Questions 417k
  • Answers 417k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The one thing I tell everybody: This is a knowledge… May 15, 2026 at 9:43 am
  • Editorial Team
    Editorial Team added an answer You can either hide or dispose of the current JFrame.… May 15, 2026 at 9:43 am
  • Editorial Team
    Editorial Team added an answer This could be due to the fact that IE6 does… May 15, 2026 at 9:43 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.