0

I have an XML file like

<?xml version="1.0" encoding="UTF-8"?> <form> <field name="age" type="list" default="1" description="age" label="Age" size="1" > <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </field> </form> 

I need to repeat the option for a fixed number of times. How can I write a loop to repeat the option? Is it possible to write a loop?

2
  • 1
    Program XML is like drive a street. You need a car, or in your case, a programming language. Which one do you use? Commented May 7, 2015 at 6:34
  • @Andreas Hey, I love this comparison. It will be great to have in mind to explain what XML don't do. Commented May 7, 2015 at 8:23

2 Answers 2

2

How can I write a loop to repeat the option? Is it possible to write a loop?

No, XML is a markup language, not a programming language. The only way to have 4 of something is to replicate it 4 times.

Sign up to request clarification or add additional context in comments.

Comments

-1

Via php

/* $xmlstr your xml string */

$options = new SimpleXMLElement($xmlstr); /* For each <character> node, we echo a separate <name>. */ foreach ($options->options as $option) { echo $option->value, $character->actor, PHP_EOL; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.