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

  • Home
  • SEARCH
  • 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 8527735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:38:23+00:00 2026-06-11T08:38:23+00:00

How would you print an Ability -elements Default -attribute value on the following XML

  • 0

How would you print an Ability-elements Default-attribute value on the following XML if you only have the element’s name and the ability id?

For example if I have the name ‘steve’ and id 1003 how would I then select and print that ability default value which is ‘false’.

<Item Id="1">
<Name>Batman</Name>
<Ability Id="3001" Default="true">Super Strength</Ability>
<Ability Id="3002" Default="false">Master martial artist</Ability>
<Ability Id="3003" Default="false">Access to high tech</Ability>
</Item>

<Item Id="2">
<Name>Superman</Name>
<Ability Id="3004" Default="true">Flight</Ability>
<Ability Id="3005" Default="false">Super Strength</Ability>
<Ability Id="3006" Default="false">Super Speed</Ability>
<Ability Id="3007" Default="true">Stamina</Ability>
<Ability Id="3008" Default="false">Invulnerability</Ability>
</Item>

<Item Id="3">
<Name>Spiderman</Name>
<ScopeNotes/> <HistoryNotes/>
<Ability Id="219" Default="false">Super Reflex & Agility</Ability>
<Ability Id="567" Default="true">Spider Sense</Ability>
</Item>

<Item Id="4">
<Name>Steve</Name>
<Ability Id="1007" Default="false">Cake eating</Ability>
<Ability Id="1001" Default="true">Swearing</Ability>
<Ability Id="1002" Default="false">Watching movies</Ability>
<Ability Id="1003" Default="false">Steve</Ability>
</Item>

The problem is that each element has a different number of ability nodes and that the name ‘Steve’ occurs both in the name and ability node.

Ive read through the php dom documentation and have used it before to loop through items and obtain names (e.g.new DOMDocument, loading a file, getElementsByTagName) but I am having difficulty understanding how it works when you attempt do do something like I have explained above.

  • 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-11T08:38:24+00:00Added an answer on June 11, 2026 at 8:38 am

    As suggested By Bob Fincheimer, XPath should be a good approach.
    The following path should give you the result

    //Item[Name="Steve"]/child::Ability[@Id="1003"]/@Default
    

    Explanation of the path:

    1. //
      select nodes everywhere in the document(I don’t know the complete xml)
    2. Item
      select <Item>-nodes
    3. [Name="Steve"]
      select nodes that have a child-element <Name> with the nodeValue “Steve”
    4. child::Ability
      select child-nodes <Ability>
    5. [@Id="1003"]
      select Nodes with a Id-attribute set to 1003
    6. @Default
      select the Default-attribute

    For the given XML it will return a DOMNodeList with 1 attribute-node (@Default="false")

    How to use it? http://www.php.net/manual/de/domxpath.query.php

    Demo: http://codepad.org/qtgWXFtm

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

Sidebar

Related Questions

For example: print('items %05d'%12) would print 00012. Can the amount of padding be specified
I would like to have the ability to process Win32 messages in a console
I need a for loop which would print from year 2000 to 2099. [Bindable]
In a basic Unix-shell app, how would you print to stdout without disturbing any
In Python, I'd like to write a function that would pretty-print its results to
I would like to print the size of the root volume set by GetDiskFreeSpaceEx(...),
I would like to print a message if either a or b is empty.
I would like to print scrollable div as WYSWYG. Is there a way?
I would like to print an array to a file. I would like the
I would like to print the selected values of all selects using jQuery. 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.