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