473,386 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 2325
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 (at least to me) is to "flatten" values that are...
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. But, Python does not a have very good macro...
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 structure. I don't care much about format, as long...
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 like to ask things differently. Basically, I'm...
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 mechanisms for retrieving values from basic text...
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 db, (we do a total of about 8 calls to the db). As...
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, each line looks like this: BLAT Search Results ...
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 validation error that occurs inside the db2 sp during...
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. layout 2. what data to show 3. what controls to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.