Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. inserting xml nodes based upon an expression

inserting xml nodes based upon an expression

Scheduled Pinned Locked Moved XML / XSL
xmlquestioncsharpphpperformance
7 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jan Limpens
    wrote on last edited by
    #1

    Hi folks, I bind textboxes to nodes of an XmlDocument and refer to these nodes via an xpath statement. Updating existing content is really easy this way. My problems arise, when I try my xpath statement does not find the node in question and subsequentially I want to create it. Say, my xpath is "/def:Version/def:Entry[lang('en')]/Title" and the second element does not exist. At first I thought, I'd split my path into pieces, ininerate it backwards, reach the first existing node and then recreate the requested structure. This could work with very easy queries, but something like "def:Entry[lang('en')]" already would require my program to "understand" that it needs to create a from the xPath lang() function. I would end up writing a strange kind of xpath parser. And the idea isn't so good either, because I'd have to make my xpath super verbose, so that no elements (attributes!) are left out (and therefore could be created at need), which doubtlessly would decrease performance. I stumbled across a xupdate implementation at http://www.openvue.net/projects.php?menu=4 It's nunit testcases don't work 100% so I would have to invest some more time into this. That's why I wanted to ask you guys, what do you think: Xupdate is the way to go for me, or do you have any other good ideas? Thanks in advance, Jan

    G 1 Reply Last reply
    0
    • J Jan Limpens

      Hi folks, I bind textboxes to nodes of an XmlDocument and refer to these nodes via an xpath statement. Updating existing content is really easy this way. My problems arise, when I try my xpath statement does not find the node in question and subsequentially I want to create it. Say, my xpath is "/def:Version/def:Entry[lang('en')]/Title" and the second element does not exist. At first I thought, I'd split my path into pieces, ininerate it backwards, reach the first existing node and then recreate the requested structure. This could work with very easy queries, but something like "def:Entry[lang('en')]" already would require my program to "understand" that it needs to create a from the xPath lang() function. I would end up writing a strange kind of xpath parser. And the idea isn't so good either, because I'd have to make my xpath super verbose, so that no elements (attributes!) are left out (and therefore could be created at need), which doubtlessly would decrease performance. I stumbled across a xupdate implementation at http://www.openvue.net/projects.php?menu=4 It's nunit testcases don't work 100% so I would have to invest some more time into this. That's why I wanted to ask you guys, what do you think: Xupdate is the way to go for me, or do you have any other good ideas? Thanks in advance, Jan

      G Offline
      G Offline
      George L Jackson
      wrote on last edited by
      #2

      I am confused on what you are attempting to do. I use a key to find nodes that need updating. If a key is not present, I find nodes via its parents or search for nodes that are missing certain child nodes or attributes. You may need to just determine if the structure of your XML document is right for what you are trying to do.

      J 1 Reply Last reply
      0
      • G George L Jackson

        I am confused on what you are attempting to do. I use a key to find nodes that need updating. If a key is not present, I find nodes via its parents or search for nodes that are missing certain child nodes or attributes. You may need to just determine if the structure of your XML document is right for what you are trying to do.

        J Offline
        J Offline
        Jan Limpens
        wrote on last edited by
        #3

        Imagine the following xml: xxx yyy zzz I query: /foo/bar[action='1']/element I get "xxx" and I can update it. Good. I query: /foo/bar[action='4']/element Now, this node does not exist, so it should be created (and it's predecessor bar with the attribute action=4). foo exists, so nothing needs to be done for it. Same aplies for /foo/bar[4]/element, just the attribute has to come from somewhere else (I can provide for this). /foo/bar[5]/element should fail This is not for a special xml file, but a generic solution, so it does not depend on any certain structure... Does this make things a bit clearer? -- modified at 16:53 Thursday 21st September, 2006

        G 2 Replies Last reply
        0
        • J Jan Limpens

          Imagine the following xml: xxx yyy zzz I query: /foo/bar[action='1']/element I get "xxx" and I can update it. Good. I query: /foo/bar[action='4']/element Now, this node does not exist, so it should be created (and it's predecessor bar with the attribute action=4). foo exists, so nothing needs to be done for it. Same aplies for /foo/bar[4]/element, just the attribute has to come from somewhere else (I can provide for this). /foo/bar[5]/element should fail This is not for a special xml file, but a generic solution, so it does not depend on any certain structure... Does this make things a bit clearer? -- modified at 16:53 Thursday 21st September, 2006

          G Offline
          G Offline
          George L Jackson
          wrote on last edited by
          #4

          I cannot see your XML. Use "Ignore HTML tags in this message ...".

          J 1 Reply Last reply
          0
          • G George L Jackson

            I cannot see your XML. Use "Ignore HTML tags in this message ...".

            J Offline
            J Offline
            Jan Limpens
            wrote on last edited by
            #5

            this should be better, now

            1 Reply Last reply
            0
            • J Jan Limpens

              Imagine the following xml: xxx yyy zzz I query: /foo/bar[action='1']/element I get "xxx" and I can update it. Good. I query: /foo/bar[action='4']/element Now, this node does not exist, so it should be created (and it's predecessor bar with the attribute action=4). foo exists, so nothing needs to be done for it. Same aplies for /foo/bar[4]/element, just the attribute has to come from somewhere else (I can provide for this). /foo/bar[5]/element should fail This is not for a special xml file, but a generic solution, so it does not depend on any certain structure... Does this make things a bit clearer? -- modified at 16:53 Thursday 21st September, 2006

              G Offline
              G Offline
              George L Jackson
              wrote on last edited by
              #6

              :confused: I lose it right after "Now, this node does not exist, so it should be created". If you are trying to write generic code to act on any XML structure, you probably have to determine its schema beforehand.

              J 1 Reply Last reply
              0
              • G George L Jackson

                :confused: I lose it right after "Now, this node does not exist, so it should be created". If you are trying to write generic code to act on any XML structure, you probably have to determine its schema beforehand.

                J Offline
                J Offline
                Jan Limpens
                wrote on last edited by
                #7

                Probably, looking up the schema is a good idea and I am not at all against it. The problem is, that mingling xpath with schema to create missing nodes via dom is something extremely complicated. I wouldn't even know where to start. That's why I thought, that XUpdate would help me there, as it is an developed language for more or less this purpose. At least I am thinking it is. I just looked it up a few days ago and haven't found anything better since. But I have no idea, if XUpdate does not have any pitfalls I am not aware of, if the implementation, I found, is ok and most importantly, if there isn't some other, more straight forward way. As for explaining my somewhat confusing (I admit) text: I wrote a provider that allows me to update and delete nodes via xpath. That's something quite easy. Now I needed to insert nodes as well and as the xpath was something I already had in my classes, I tried to implement the insert as well via xpath. I failed at that and I am pretty sure that xpath just is not the right expression for the job. Even though others at cp have tried something quite similar: http://www.codeproject.com/csharp/xpathstore.asp So my examples have to be read with that bias: to use an xpath as an more or less equivalent to an sql insert statement.

                I query: /foo/bar[action='4']/element Now, this node does not exist, so it should be created (and it's predecessor bar with the attribute action=4). foo exists, so nothing needs to be done for it. Same aplies for /foo/bar[4]/element, just the attribute has to come from somewhere else (I can provide for this). /foo/bar[5]/element should fail (because there is no element bar[4] for it to be inserted after)

                Thanks for sharing your thoughts! Jan

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups