Thread: XML Help Needed

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    63
    Rep Power
    14

    XML Help Needed


    Say I have a simple XML file including this:
    Code:
    <ProductInfo>The <item>shirt</item> comes in 3 sizes.</ProductInfo>
    <Comments>One <item>shirt</item> costs 10</Comments>
    I need the XML file to know that the two instances of "shirt" are the same, so something like this:
    Code:
    <ProductInfo>The <item id="S3"/> comes in 3 sizes.</ProductInfo>
    <Comments>One <item id="S3"/> costs 10</Comments>
    <item id="S3" name="shirt"/>
    ...something to that effect, but obviously I'm doing it the wrong way.

    What I want to achieve is a document that will look like this:

    The shirt comes in 3 sizes.
    One shirt costs 10

    ...so if I change "shirt" to "t-shirt" it will change in both places.

    I'm finding it quite difficult to explain, but I hope you understand and can help me.

    Thanks.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Posts
    81
    Rep Power
    14
    What are planning to use to generate the resulting document? Because on it's own XML is just a tag language and there are many applications/ways of transforming XML into something viewable.

    Also, typically one would not mix data with pseudo-formatted output in the same document. Usuallly you have things broken into data and view transforms.

    For example, if you use XML with XSL, you might have the following documents. Your XML document would have the data:

    <item type="shirt" cost="10" numsizes="3"/>

    And your XSL document would define how to output that into say HTML. Here's an XSL fragment:

    <xsl:template match="item">
    <p>The <xsl:value-of select="@type"/> comes in <xsl:value-of select="@numsizes"/> sizes.</p>
    </xsl:template>

    So the key is how do you plan to view your XML?
    Robert Dominy
    About Guide for JavaScript
    http://javascript.about.com
    Software Consulting & Development
    http://www.angusog.com

IMN logo majestic logo threadwatch logo seochat tools logo