PDA

View Full Version : Referring to XML Elements inside another Element


wfsaxton
12-01-2005, 09:29 PM
Supposed I have an element "bank" which contains "dimm" elements:

<bank>
<dimm label="J0"><size>1GB</size><brand>A</brand></dimm>
<dimm label="J1"><size>1GB</size><brand>B</brand></dimm>
</bank>

Now, I have a second element "systemboard" which I also want to contain the "dimm" information. I don't, however, want to replicate the above "dimm" elements.

The best example I can think of is this kludgy code:


<systemboard>
<dimm_pointer label="J0"/>
</systemboard>

I'm an XML noob so I'm figuring that has to be a better "standard" way of doing this kind of stuff. Any ideas?

I should note that this information is being stored in a database. The 'bank' and 'systemboard' elements will be in different fields.

Alex Vincent
12-02-2005, 03:26 AM
Pure XML doesn't have much better to offer you; in the first case, you want an ID-type attribute, and in the second, you want IDREF-type. But that's just semantics, and doesn't copy the data.

XSLT probably has a cross-browser solution for you. XBL certainly could do that (but that's Mozilla-only). Server-side, especially from a database, you have lots of options, including PHP and Perl.

wfsaxton
12-02-2005, 03:58 PM
I'm not looking for answers on how to display the data so much as how to establish a relationship.

I guess I was just looking for something simple that I overlooked. Someone else at my work suggested something like:

<systemboard number="1">
<dimm number="1" bank="1"><kb>1000</kb><brand>A</brand></dimm>
.
.
</systemboard>

Making 'bank' a label makes it more difficult to retrieve, but since it isnt' as important of a relationship, it makes the schema a lot easier.

Thanks.