473,402 Members | 2,061 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,402 software developers and data experts.

Insering a node via an expression

Hello,

I am creating a simple CRUD application which uses xml files as data
storage. I extended Textbox with a XPath expression and a XmlDocument
property, this way I can easily read and update existing nodes' content.
I was very happy with the solution until the first time I needed to
insert a hierarchy of nodes. Imagine the following situation:

<Entry>
<Version xml:lang="en">
<Text>foo</Text>
</Version>
<Version xml:lang="de">
<Text>fu</Text>
</Version>
</Entry>

I select "<Entry/Version[lang('fr')]/Text" and receive null. There is no
such node, so I wanted it to be created - but how???
Of course I could hard code every conceivable situation in c#, but ... I
don't have to go into this. Something like this must have a somehow
expression triggered mechanism that does the dirty work. I would not
even know which syntax to use.

I could chop my expression into pieces and iterate it backwards until I
find a valid node - in this case <Entry>, then I would have to create
the counterpart of "Version[lang('fr')]" - which is <Version
xml:lang="fr">, but I needed to implement all XPath & DOM functions, to
be able to guess that.

Schema could help me. If my XmlDocument had a schema it would be somehow
possible to construct a prototype xml fragment that I could insert in
the right spot, but this in interaction with XPath goes way beyond my
programming skills.

Inventing a XPath inspired insert syntax like
XmlNode myNode =
XmlInserter.InsertNode("/Entry/Version@xml:lang='de'@something='xx'/Title");
myNode.InnerText = "bar";
does not seem a good idea to me. That's something consortiums do...

I cannot imagine that this problem is so uncommon, that there are no
proven solutions for it. I am just being blind and/or unimaginative, I
guess. As I am pretty lost, I'd be extremely happy for any hint into the
right direction!

Jan
Sep 16 '06 #1
1 1466
"Jan Limpens" <1s*****@lastname.comwrote in message
news:O0**************@TK2MSFTNGP05.phx.gbl...
I cannot imagine that this problem is so uncommon, that there are no
proven solutions for it. I am just being blind and/or unimaginative, I
guess. As I am pretty lost, I'd be extremely happy for any hint into the
right direction!
Jan, you're not the only person who has wanted a way to create an XML
document, or pieces of one, from a schema. Unfortunately, there was no
solution for the others, either.

This may, in part, be due to the fact that your problem statement
presupposes the solution to the problem. To restate:

1) Given a text box combined with an XPath expression and an XmlDocument,
and
2) Given that the XPath expression, when applied to the XmlDocument,
provides the content of the text box, then

How do you use the changed content of the text box to create the node or
nodes implied by the XPath expression?

The above requires the solution to your larger problem (creating nodes if
they didn't exist) to be in terms of your smaller problem (displaying the
nodes if they exist). It's possible that you need to solve the larger
problem first, after which the smaller problem will solve itself.
Another suggestion I would make would be that you should separate data and
presentation. Tying a presentation element to data storage is a bad
architecture. Among other problems that come to mind, how would you handle
a combo box or even radio buttons? This simple concept of an XPath
expression doesn't adequately cover even the most basic user interface
elements, once you get past text boxes.

Even with text boxes, your paradigm doesn't seem to cover validation.

I think you should probably broaden your problem definition, after which
you'll realize that this is not a problem that can be solved by one person.

I would wish to draw your attention, and that of anyone else with a similar
problem, to a commercial solution to this general problem of producing a
CRUD user interface based on XML Schema: Microsoft Office InfoPath
(http://msdn.microsoft.com/office/program/infopath/). Even if you strip off
all the fancy "Office" features, you'll find that the work involved in
creating a general solution to this XML Schema UI problem is substantial.

John
Sep 16 '06 #2

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

Similar topics

3
by: ricky | last post by:
I want to return with only one xpath expression the first following node relative to a node with a XPTO attribute. Example: <node> xxx </node> <node XPTO="true"> yyy
2
by: Steve Jorgensen | last post by:
Working with the DOM (specifically, the MSXML DOM), I'm wondering if there's an efficient way to check whether it would be matched by a given XPath expression. I've made it work to just run the...
4
by: Jim Garrison | last post by:
I know how to use the name() function to access the name of the current node. How do I get the 'fully qualified' name, consisting of the path from the root to the current node? I.e. <a> <b>...
1
by: Rob | last post by:
Hi, I am moving through an XML document using an XPath Navigator, and I'd like to be able to get the xpath expression for the location of the current node from the root node. Any ideas how to...
8
by: Jean-François Michaud | last post by:
Who in the name of #%@! thought this one out?? I noticed this behavior when trying to debug a problem I was having. I used this logical expression and some XPATH in a specific sequence of...
4
by: MA | last post by:
Hi, How to access the total number of child nodes from a parent node. For example, I would like to get the total number of child nodes from <parent1and <parent2node. The SelectNodes method...
2
by: Werner Sammer | last post by:
I would like to load an XML document from say D:\mytask\mydoc.xml into a CSharp and to retrieve from the resulting XML node tree a certain node/element by specifing an XPath expression. Does...
4
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
Hi; If I have an XPathNavigator object and for a given xpath statement need to know if the node exists, how should I do this? I have found for some xpath functions it returns an empty string if...
5
by: jorgedelgadolopez | last post by:
Hi all, I am using the xpathnavigator evaluate function on .net (xpath 1 right?). Now I need to expand the code to do multiple contains, compare dates (such as 'before', 'between' and 'after'),...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.