473,785 Members | 2,794 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Ins ertNode("/Entry/Version@xml:lan g='de'@somethin g='xx'/Title");
myNode.InnerTex t = "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 1486
"Jan Limpens" <1s*****@lastna me.comwrote in message
news:O0******** ******@TK2MSFTN GP05.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
3489
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
1516
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 XPath select on the document, looping through all the nodes returned, and seeing if one of those is the same as the node in question. If I need to check many expressions, though, this would not be efficient.
4
4154
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> <c> </c> </b>
1
10959
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 do this? I was hoping for a property of the navigator object, but I can't find it..... Thanks in advance for any help!
8
2198
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 instructions that allow me to transform a CALS table model into our own specific table model and I used this expression: <xsl:if test="self::node()=../CELL and self::node()">...
4
6498
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 return the total number of <foldernodes (9) regardless of calling from the <parent1> and <parent2node. XML: ----------------------------------
2
1271
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 someone know a simple CSharp sample source which shows how to implement this task ? Werner
4
8779
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 the node does not exist but that is also the result for an empty node. -- thanks - dave david_at_windward_dot_net
5
50583
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'), and so on. This is the thought: //person
0
10329
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
10152
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
10092
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,...
0
8974
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5381
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...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
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
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
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.