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

The Archive Base Latest Questions

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

I am trying to create a page which will show specific information from an

  • 0

I am trying to create a page which will show specific information from an XML document. I have run into a snag where I would like to find out the best possible way to do this.

My XML is a large list that is built from a program called Army Builder. I am trying to dynamically pull specific information for each “squad”.

Right now, a sample of my code looks like this:

<?PHP  
        //THIS SECTION FINDS THE SQUAD/UNIT NAME OF THE FIRST ENTITY
        foreach($squad->xpath('entity') as $squadSub){
            $squadSubName = stripslashes($squadSub['name']);
            $squadSubCount = $squadSub['count'];


            foreach($squadSub->xpath('unitstat[@id="WS"]/@value') as $squadSubStat){
                $unitWs = $squadSubStat;
            }

        ?>
        <tr>
            <td><?= $squadSubCount; ?></td><td><?= $squadSubName; ?></td><td><?= $unitWs; ?></td><td><?= $unitBs; ?></td><td><?= $unitSt; ?></td><td><?= $unitTo; ?></td><td><?= $unitWo; ?></td><td><?= $unitIn; ?></td><td><?= $unitAt; ?></td><td><?= $unitLd; ?></td><td><?= $unitaSv; ?></td><td><?= $unitiSv; ?></td><td><?= $unitcSv; ?></td>
        </tr>

The line that finds the “unitWS” is what I am asking about. Now, if you follow the entire xpath, it would read //squad/entity[@name='Nameoftheentity']/unitstat[@id="WS"]/@value and that would give me the unit’s WS. I need to pull 8-13 more values from the xml.

I will show you the /unitstat section of the XML:

<unitstat id="iaStruPnt" name="Structure" value="-" />
         <unitstat id="iaVdShld" name="Void Shld" value="-" />
         <unitstat id="vdrAt" name="At" value="-" />
         <unitstat id="vdrBS" name="BS" value="-" />
         <unitstat id="vdrMass" name="Mass Point" value="-" />
         <unitstat id="vdrSize" name="Size" value="Small" />
         <unitstat id="vdrTpt" name="Transport" value="0" />
         <unitstat id="vdrVehSv" name="Veh Save" value="-" />
         <unitstat id="vdrWS" name="WS" value="-" />
         <unitstat id="vdrWpnAP" name="AP" value="-" />
         <unitstat id="vdrWpnRang" name="Range" value="-" />
         <unitstat id="vdrWpnSh" name="Shots" value="-" />
         <unitstat id="vdrWpnStr" name="S" value="0" />
         <unitstat id="vdrWpnType" name="Type" value="0" />
         <unitstat id="At" name="At" value="2/3" />
         <unitstat id="BS" name="BS" value="4" />
         <unitstat id="Fam" name="Familiar" value="0" />
         <unitstat id="Front" name="FA" value="0" />
         <unitstat id="Group" name="Grp" value="" />
         <unitstat id="In" name="In" value="4" />
         <unitstat id="Ld" name="Ld" value="10" />
         <unitstat id="Rear" name="RA" value="0" />
         <unitstat id="Save" name="Save" value="2+/5(i)" />
         <unitstat id="Side" name="SA" value="0" />
         <unitstat id="St" name="St" value="4" />
         <unitstat id="To" name="To" value="4" />
         <unitstat id="WS" name="WS" value="4" />
         <unitstat id="Wo" name="Wo" value="1" />
         <unitstat id="iaAmmo" name="Ammo Load" value="0" />
         <unitstat id="iaCrew" name="Crew" value="-" />
         <unitstat id="iaMinRge" name="Min Rge" value="n/a" />
         <unitstat id="iaPowField" name="PowerField" value="-" />

I need to pull the VALUES of At, BS, In, Ld, St, To, Ws , Wo and Save for each dynamically found unit. The only way I see it possible is to type this:

foreach($squadSub->xpath('unitstat[@id="WS"]/@value') as $squadSubStat){
    $unitWs = $squadSubStat;
}

for every one of the values and for every one of the sub groups. Is there an easier way to get all of those values from the specific ID’s that I need?

I would assume that I should create an array, then call through them?

Please let me know if you need more information!

  • 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-24T05:43:17+00:00Added an answer on May 24, 2026 at 5:43 am

    With the “or” operator?

    <?php
    $squadSub->xpath('unitstat[@id="WS" or @id="BS" or @id="whatever"]/@value');
    

    edit:
    Sorry I misunderstood. Here is my proposition:

    <?php
    $units = array();
    
    foreach (array('WS', 'BS', 'Save') as $id)
    {
        if ($tmp = $squadSub->xpath("unitstat[@id='$id']"))
            $units[$id] = (string)$tmp[0]['value'];
    }
    
    print_r($units);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ive been trying to create a testimonial section for a page which will have
I am trying to create a function which will extract meta keywords from a
I'm trying to create a efficient query which will retrieve 'projects' from a database
I am trying to add a page to my application which will show a
I'm trying to create a stored procedure which will fetch data from sys.databases and
I am trying to create a glossary system which will get a list of
I am trying to create controller actions which will return either JSON or partial
I am trying to create pager which will sit in the center of the
I am trying to create an autocomplete textbox using jquery which will be bound
I am trying to create an Open button which will open a new website.

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.