472,353 Members | 1,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

DOM as a flat dictionary

Until now I have been using XSLT to translate from a known foreign XML
format to a local XML format for import to Postgres. Now I need to be able
to let others define the relationship from new foreign documents using a
gui.

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?

And has anyone written such a thing, even in part?

Many thanks,
Christopher Boomer
Belfast.
Jul 18 '05 #1
2 2279
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
Jul 18 '05 #2
Neil Padgen <ne*********@mon.bbc.co.uk> wrote in message news:<bg**********@nntp0.reith.bbc.co.uk>...
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.
You'll lose any ordering of the elements.


Not if you employ position indicators, as defined in XPath. Of course,
this might not make the "flat" descriptors very readable, but there
are other solutions.
With the XML

<spam>
<eggs/>
<bacon/>
<lobster_thermidor accompaniment="crevettes" sauce="mornay"
topping="fried_egg">
<more_spam/>
<lobster_thermidor>
Editing this to be a closing tag, of course...
</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.


You could employ something like this:

/spam/*[1] -> refers to "eggs"
/spam/*[2] -> refers to "bacon"

This isn't nice to read, as I noted above, and in practice it would
also rely on you having some kind of schema information for you to
know in advance which kind of element was being referred to. For the
desired application, I doubt that this is acceptable.

You could make things more complicated:

/spam/eggs[position() = 1] -> refers to "eggs" but only as the
first element in the sequence
/spam/bacon[position() = 2] -> refers to "bacon" but only as the
second element in the sequence

This does indicate which element is being referred to and where that
element resides in the sequence of elements. The reconstruction of a
document from this information could be easy enough to achieve,
although the parsing of the conditional part is slightly more
complicated than other (non-XPath) notations.

You could invent a simplified (non-XPath) notation:

/spam/eggs:1 -> refers to "eggs" but only appearing first
/spam/bacon:2 -> refers to "bacon" but only appearing second

In the past, I've adopted such notations myself in order to represent
hierarchies in rendered HTML forms. There can be alternative
interpretations of the position numbers, however, since if you have a
schema to work from then you could decide to interpret the numbers as
the position of a particular element amongst elements of only that
kind, comparable to the following XPath expressions:

/spam/eggs[1] -> refers to the first "eggs" element
/spam/bacon[1] -> refers to the first "bacon" element
(not giving any information about the relative
ordering of different elements)

There are plenty of alternatives, so I hope one of them is useful. :-)

Paul
Jul 18 '05 #3

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

Similar topics

11
by: Nicolas Girard | last post by:
Hi, Forgive me if the answer is trivial, but could you tell me how to achieve the following: {k1:,k2:v3,...} --> ,,,...] The subtle point...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn....
3
by: Ksenia Marasanova | last post by:
I get this kind of list from a database. (The tuple structure is: id, name, parent_id) I would like to transfer it (in Python) into a tree...
13
by: raykyoto | last post by:
Hi all, I'm sure this is a popular question that comes up every few months here. Indeed, I've looked at some of the past postings, but I would...
22
by: Daniel Billingsley | last post by:
Ok, I wanted to ask this separate from nospam's ridiculous thread in hopes it could get some honest attention. VB6 had a some simple and fast...
9
by: FFMG | last post by:
In my site I have a config table, (MySQL), with about 30 entries; the data is loaded on every single page load. This is not the only call to the...
0
by: moconno5 | last post by:
Hello again, I am still working on my same project and have run into another little problem. I have created a flat file with data from a server,...
2
by: murthydb2 | last post by:
Hi My requirement is that i have to write a stored procedure in db2 and that will be executed in a batch file . Any system error or...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1....
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

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.