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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:33:05+00:00 2026-05-24T00:33:05+00:00

I wan’t to load some data from my XML file using this function: public

  • 0

I wan’t to load some data from my XML file using this function:

public function getElements()
{
    $elements = array();

    $element = $this->documentElement->getElementsByTagName('elements')->item(0);

    // checks if it has any immunities
    if( isset($element) )
    {
        // read all immunities
        foreach( $element->getElementsByTagName('element') as $v)
        {
            $v = $v->attributes->item(0);

            // checks if immunity is set
            if($v->nodeValue > 0)
            {
                $elements[$v->nodeName] = $v->nodeValue;
            }
        }
    }

    return $elements;
}

I wan’t to load that elements from my XML file:

<elements>
    <element physicalPercent="10"/>
    <element icePercent="10"/>
    <element holyPercent="-10"/>
</elements>

I wan’t to load only element node name and node value.

Got this code in my query loop:

            $elements = $monster->getElements();
            $elN = 0;
            $elC = count($elements);
            if(!empty($elements)) {
                foreach($elements as $element => $value) {
                    $elN++;
                    $elements_string .= $element . ":".$value;
                    if($elC != $elN)
                        $elements_string .= ", ";
                }
            }

And finally – the output of $elements_string variable is wrong:

earthPercent:50, holyPercent:50, firePercent:15, energyPercent:5, physicalPercent:25, icePercent:30, deathPercent:30firePercent:20, earthPercent:75firePercent:20, earthPercent:75firePercent:20, earthPercent:75physicalPercent:70, holyPercent:20, deathPerce

It should rather return:

physicalPercent:10, icePercent:10, holyPercent:-10

Could you help me one more time?:)

Thank you in advance.

  • 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-24T00:33:08+00:00Added an answer on May 24, 2026 at 12:33 am

    Well the XML-Parser doesn’t magically know which elements you want to load and which you won’t – you have to filter this by yourself. Then you have to decide where you want to filter your desired elements in the getElements-function you posted or in your “query loop” as you call it.

    Should the getElements be some kind of general function which must return all elements? Then you should change that check if($v->nodeValue > 0) to something like if(!empty($v->nodeValue)) otherwise you wont get the “holyPercent” value since this is negative (and the old expression becomes false).

    Then in your “query loop”, just select your desired elements:

    foreach($elements as $element => $value) {
        if(in_array($element, array("physicalPercent", "icePercent", "holyPercent"))) {
            $elN++;
            $elements_string .= $element . ":".$value;
            if($elC != $elN)
                $elements_string .= ", ";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wan to remove the last set of data from string using java. For
I wan't to get data's from CallLog.Calls.CONTENT_URI in non Activity classes. Am using cursor
I wan't to hide/show menuitems in a contextmenu using some propery of databound object.
I wan't to search a filename for example like this string: $filetype = file.php.jpg;
I wan t to upload the xml data to the sql table. I am
I wan't to post a CSV file to a web service using the Jersey
I wan't to know the best method to load image asynchronously from Mysql in
I am parsing an XML but having some problem regrading its attribute. I wan
I wan't to do some calculated pixelart with OpenCL and display this directly on
I wan't to change the background color of a div dynamicly using the following

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.