The object model is one side of the equation; the other side is the XML file. In an ideal world, the XML file would match your object structure exactly and would be similar to the following: <?xml version='1.0'encoding='ISO-8859-1'?> <Catalog> <VisualProduct> <Id>wp01</Id> <Checked>false</Checked> <Name>WhizBang Word Processor</Name> <Image>images/wordprocessor.jpg</Image> </VisualProduct> <TextualProduct> <Id>li04</Id> <Checked>false</Checked> <Title>WhizBang Bright Light</Title> <Descriptions> <Description> <Language>EN</Language> <Text>With power saving.</Text> </Description> <Description> <Language>FR</Language> <Text>Avec gestion d'nergie.</Text> </Description> </Descriptions> </TextualProduct> </Catalog>
However, that is the ideal case. In practice, the product information comes from the central database, so chances are the XML file will be closer to the database organization than to your object model. It is not unlikely that the file will look similar to Listing 1.7. Obviously, because it is based on the same list of products, Listing 1.7 is not completely alien to your object model either. The major difference is that it doesn't have a VisualProduct or TextualProduct . In Listing 1.7, every entry is a product. Listing 1.7's structure is illustrated in Figure 1.4. Listing 1.7 catalog.xml<?xml version='1.0'encoding='ISO-8859-1'?> <Catalog> <Product id='wp01'checked='false'> <Text>WhizBang Word Processor</Text> <Image>images/wordprocessor.jpg</Image> </Product> <Product id='sf02'checked='false'> <Text>WhizBang Safest Safe</Text> <Image>images/safe.jpg</Image> </Product> <Product id='ca03'checked='false'> <Text>WhizBang Good Calculator</Text> <Image>images/calculator.jpg</Image> </Product> <Product id='li04'checked='false'> <Text>WhizBang Bright Light</Text> <Descriptions> <Text xml:lang='EN'>With power saving.</Text> <Text xml:lang='FR'>Avec gestion d'nergie.</Text> </Descriptions> </Product> </Catalog> Figure 1.4. XML document structure.
|