DOM as a flat dictionary

Neil Padgen neil.padgen at mon.bbc.co.uk
Mon Jul 28 11:45:39 EDT 2003


On Friday 25 July 2003 13:38, don't dash! wrote:

> My thought was to generate a flat dictionary representation of the
> foreign
> and local formats with the absolute Xpath expression as dictionary
> key.  The user is presented with a list of elements&attributes in
> the local file and
> asked to select the foreign element|attribute fills that role.  I
> could then use the keys from this mapping to generate XSLT which can
> be stored.
> 
> Using dictionary keys means that duplicate elements will be lost,
> but this is not problematic since I am attempting to map the
> structure not the
> content.  What are the other implications of this approach?  Or is
> there an easier way to do what that I cannot find in Google?

You'll lose any ordering of the elements.

With the XML

<spam>
  <eggs/>
  <bacon/>
  <lobster_thermidor accompaniment="crevettes" sauce="mornay"
                     topping="fried_egg">
    <more_spam/>
  <lobster_thermidor>
</spam>

translated into a flat dictionary

{
  '/spam': True,
  '/spam/eggs': True,
  '/spam/bacon': True,
  '/spam/lobster_thermidor': True,
  '/spam/lobster_thermidor/more_spam': True,
}

there is no way that you can tell whether /spam/eggs comes before
/spam/bacon in the original XML.

-- Neil




More information about the Python-list mailing list