473,763 Members | 7,541 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML parse/build metaphor mismatch

I'm wondering if there's an approach to writing consistent code to read/write
XML data in arbitrary order that I'm simply missing.

It seems to be easy getting stuff -out- of a DOM via XPath, but it's much
tougher building a DOM document in arbitrary order. Yes - I can get the
parent context element first, using XPath, but then I build custom wrappers
and helpers to simplify the building and adding fragments in the correct
namespace, etc. Adding attributes is especially wierd and unneccessarily
cumbersome.

I can reuse my own libraries across applications, of course, but I've
essentially invented my own private code island at this point for something
everyone has to do when building XML documents using the DOM. What I end up
with doesn't nicely mirror how we use XPath to read content out, so I have
more duplication than I'd like between the code that reads and writes any
particular document type.

I keep wishing that XPath or XQuery would be more like SQL inasmuch as a
simple SQL expressions can add or update a record in a table in a syntax
independent of the database library employed (e.g. UPDATE employee SET
first_name='Jan e', last_name='Doe' WHERE id=123"). Correct me if I'm wrong,
but I don't see any evidence that XQuery or any other standard XML library has
data updating capability like that.

Since I'm still fairly new to XML, I'm presuming there's at least a 50/50
chance that I'm simply making mountains out of molehills, but I see evidence
that perhaps, I am not. For instance, see "Lesson 5: Use DOM Wrapper Objects"
at http://www.developer.com/xml/article.php/2194491.

Now - imagine something like this...

document.select SingleNode(/Document/Body/Employees).modi fy("insert
Employee[@id:='123'][ Person[ Name[@first:='Jane'][@last:='Doe']
][Notes/self::text():=' Hi there']");

The format for insertion roughly mirrors the XPath predicate format, but each
expected node that did not already exist would be created, and any "="
operators perform value assignment, not comparison (other ideas are possible,
like using := for assignment). Any item we assign a value to that already has
a value (including empty-string attributes) should cause an error because we
said we were inserting. There would be a similar 'update' method for creating
new nodes as required, and also unconditionally replacing any existing node
values.

There are lost more details to work out for a full spec, of course, like
whether to support position predicates, and whether an insert should fail or
push the existing element forward in that case, etc., but it's the start of an
idea, anyway.

Now, let's add to this that the elements would be added to the DOM pretty much
as if you had typed the expanded XML text right into that point in the
document. For instance, inserted elements with no prefixes would be treated
the same as child elements with no prefixes, regardless of what namespace that
implies that they should be in (but allow overriding the default with a
defaultNamespac eURI parameter). For node names with prefices, the namespaces
should be assigned the same way they would be interpreted by a select,
depending on the settings for the DOM object.

What say y'all? Am I inventing a solution spec for a non-problem if I just
knew the best DOM coding practices, or is this somwehat on-target, and
something we should all be clammoring for?
Aug 20 '05 #1
0 1104

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

Similar topics

1
2299
by: David M Noriega | last post by:
Ok I'm no programmer but have done it in the past. I am trying to build a program from its source, its called Juk. It needs the kde bindings for GStreamer. I found them using CVS. So no I must build that. When doing so I get a parse error before token '>' for smartptr.h The line reads template <class T = Object> I've looked all around and I only can find template being used without the = Object part. And when I try removing that...
1
2492
by: LJgrnl | last post by:
I've got a type mismatch error that's driving me nutty. Variable blnNoData has the initial value False. If a recordset comes back empty (both .EOF and ..BOF are true) then blnNoData is set to True. I then have an if statement to determine what to write to the screen depending on blnNoData. As long as the if statement is true (doesn't have to go to the else clause), the code runs fine. Otherwise, a type mismatch error is returned. In...
9
3177
by: ThunderMusic | last post by:
Hi, I'm using the timespan's Parse method to build my timespan from a string. here's the line I use : m_Delay.Parse(RegKey.GetValue("Delay", "01:00:00")) the value I get from the RegKey is 00:00:30, so it should give a timespan of 30 seconds, but when I do msgbox(m_Delay.ToString), it displays 00:00:00. Am I doing something wrong?
1
2400
by: praba kar | last post by:
Dear All, I am new to python world. I have pasted my code which I used it to build rfc822 format mails for webbased mailing system task(which is like to yahoo.com web interface). Now I am asking some suggestions and guidence regarding this below code. Still What way I can improve this code. If anyone find error kindly let me know how to correct it.
6
19028
by: Ehartwig | last post by:
I recently created a script for user verification, solved my emailing issues, and then re-created the script in order to work well with the new PHP 5 that I installed on my server. After submitting user information into my creation script, I get the following error from the page that is suppose to insert the user data into the database, create a code, then send an email out for verification. Parse error: parse error, unexpected $end in...
21
2671
by: William Stacey [MVP] | last post by:
Anyone know of some library that will parse files like following: options { directory "/etc"; allow-query { any; }; // This is the default recursion no; listen-on { 192.168.0.225; }; forwarders { 4.2.2.2; }; };
12
1723
by: David Murmann | last post by:
hi all! i just built revision 41809 under winxp using a rather uncommon setup (at least i think so). since i have no visual studio here, i only used freely available tools: cygwin to get the source, the microsoft compiler/linker and NAnt (nant.sf.net) as the build tool to interpret the .vcproj-files (which may be the uncommon part). as far as i understand this setup is not supported in any way, but i noticed two problems, that could...
34
2984
by: priyanka | last post by:
Hi, I was wondering if we could parse or do something in the executable( whose source language was C). How can I use some scripting language like perl/python to find out the information about the executable ? Is it possible ? Also, how does the compiler add inling to the program ? I know that whenever it sees"inline" in front of the procedure name, it inlines it. But if we give the -finline options, it inline all the procedures ? How
4
3301
by: Peter Proost | last post by:
Hi group, it's been a long time since the last time I've been here but I have a question. I'm working with timespan.parse for calculating a duration, I have to add strings which are in the following format 15:36:12 ==Hours, minutes, seconds but sometimes there is a string like 55:26:32 ==which is correct cause the production machine was busy for 55 hours, but the timespan.parse crashes on this value because it expects 2.7:26:32. I've...
0
9386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10144
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9997
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9937
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.