473,396 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Guru Advice Requested...

disclaimer - i'm an xml newb.

my new project requires me to parse through an xml document and
populate an html form with the values. this appears simple if the
number of elements were to stay constant, however, they don't. i might
have one <element> or three <element>.

i'm using php and i'm planning on using PHP's DOM XML to parse through
the document a (using foreach) to nab each value and store it into a
variable and use those variables to display input into my forms. of
course, i'll need to use foreach in order to create my form elements,
too.

my variables would be created as follows:

$element1
$elemtent2

where the numeral is created as i loop through the values.

does this sound reasonable? is their some kind of DOM XML magic that
is designed to handle this case with ease?

any help / guidance would be greatly appreciated.

Feb 17 '06 #1
3 1137
you could use an array
$elements = array()
array_push ( $elements, $elementValue );
numberOfElements = count( $elements )
etc.

Is this what you are asking? This should be simple enough.

Feb 18 '06 #2

Skeets schrieb:
disclaimer - i'm an xml newb.

my new project requires me to parse through an xml document and
populate an html form with the values. this appears simple if the
number of elements were to stay constant, however, they don't. i might
have one <element> or three <element>.

i'm using php and i'm planning on using PHP's DOM XML to parse through
the document a (using foreach) to nab each value and store it into a
variable and use those variables to display input into my forms. of
course, i'll need to use foreach in order to create my form elements,
too.

my variables would be created as follows:

$element1
$elemtent2

where the numeral is created as i loop through the values.

does this sound reasonable? is their some kind of DOM XML magic that
is designed to handle this case with ease?

any help / guidance would be greatly appreciated.


i had nearly the same problem and solved it as follows:

first i load my XML-Data in an DOMDocument. Afterwards i label every
element with a numbered "name" tag using XPath-expression "//*".

that's it:

$xml = DOMDocument::load($_GET["xml"]);
$XPath = new DOMXPath($xml);
$r = $XPath->query("//*");
for ($i=0;$i<$r->length;$i++) {
$r->item($i)->setAttribute("name", $i);
}

For creating the form i recommend XSL.

Cheers,
Dominik

By sending the form you can recognize the data in the fields by that
name.

Feb 18 '06 #3
Skeets wrote:
i might
have one <element> or three <element>.
That is not a problem at all as there are methods like
$domDocument->getElementsByTagName('element')
or
$someElement->getElementsByTagName('element')
to give you a node list of those element nodes for further processing.
And there is the possibility to use XPath for more complicated selections.
my variables would be created as follows:

$element1
$elemtent2

where the numeral is created as i loop through the values.


Does not sound like an XML problem then, as said for the XML elements
you have a node list to process, other data structures you want to fill
then are not XML related and as already suggested PHP has arrays to
allow you to store data e.g.
$data = array();
$data[] = ...;
$data[] = ...;
will increase the length of the array with each assignment.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: obhayes | last post by:
Hi, I have two tables Table A and B, below with some dummy data... Table A (contains specific unique settings that can be requested) Id, SettingName 1, weight 2, length Table B (contains...
3
by: Richard | last post by:
Trying to wrap my brain around Regex for the first time... I need to be able to replace Sql @NamedParameters with "?" for compliance with an extremely lame 3rd party Odbc driver. I know that...
4
by: Tim::.. | last post by:
I have asked this question several times and can't seem to get the answer I am looking for! I am trying to create a form that responds dynamically to the users choises within the page. At the...
67
by: Scott M. | last post by:
Can anyone give me any ideas on why VS.NET 2003 running on XP Pro. (P4's with 1GB RAM) would take over 3 minutes to simply create a new ASP.NET Web Application on http://localhost? It seems that...
4
by: Andrey | last post by:
Hi, I will be hiring a php guru to help us architect a highly scalable web site/web application; the problem is I am coming from Microsoft .NET world and not too much familiar with the platform....
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.