Announcement

Collapse
No announcement yet.

XML Help

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [SOLVED] XML Help

    OK. A current project at work has gone awry due to a vendor not being capable of doing what needs done when creating an XML file. See below quick XML out line (crude outline). This XML has segments A, B and C that possibly can contain pertinent information. However when getting to D1.... D4 they really need to each be in their own XML file with all the preceding segments. Anyone know of a program that can help do that? Is there really a way to do that programmatically? That is, based on the below. Input A-XML and Output A1-XML. A2_XML, A3-XML and A4-XML.



    <A>
    .....<B>
    ..........<C>
    ..............<D1>
    ..............<D2>
    ..............<D3>
    ..............<D4>
    etc.
    Last edited by MoonRise; Jan 30, 2014, 09:07 PM.

    #2
    Hi moonrise!

    have you done any of that absolutely marvy artwork lately! ?

    As to your situation,....I indicated that all of that .xml crappola is in an attached file waaay back at Xandros...or maybe PClos.... but all that I, personally, could do was to "extract" the "stuff" in the non .xml part of the file, say in a word doc, the actual text.

    The .xml part of the file was a kind of a "wrapper" that would somehow "enhance" the basic "text" so that maybe images, or whatnot, could be inserted/appended to the text ...supposedly to "enhance' it so that it would somehow better interact with "stuff" ..."on the web"....at least that was what Microsith said on their website.

    And I was roundly ignored.

    Here is a very tantgential comment by me...but back then Xandros was supposed to be the "saviour" of "Linux" so that the complainers would have "compatibility" with the all seeing eye of Sauron....



    oooh sorry.... of Microsith.

    http://archive.is/72Hzs

    However..............I am WAAAY behind the times.....soooooo

    HANG ON!!! somebody that is much more current on this will happen by in the nonce.

    AAAND how about some more of that GREAT ARTWORK!!!

    woodsmoke
    Last edited by woodsmoke; Nov 13, 2013, 10:55 PM.
    sigpic
    Love Thy Neighbor Baby!

    Comment


      #3
      Thanks! As far as the artwork that has fallen victim to work. It has been really harsh this past year. This XML issue in point. Thing is, this vendor of ours is supposed to be "experts" and I know more than they and am having to find a solution to their lack of, well what ever you want to call what little they have! I'm sure a mapping type application would work but I don't have access to such a thing.

      Comment


        #4
        Originally posted by MoonRise View Post
        Is there really a way to do that programmatically?
        Anything is possible and from what you describe it shouldn't be that hard....but the devil is in the details.
        FKA: tanderson

        Comment


          #5
          Do IUC? Copy the original four times, then delete the D parts not wanted from each?

          A real, possibly obfuscated, example of the file would be helpful. I suspect vim text objects would make it a snap.

          Regards, John Little
          Regards, John Little

          Comment


            #6
            This is an EDI process. The files can be hundreds of lines long so doing a manual process would be unproductive especially when you want the process to be automated as much as possible. We have someone currently looking at using a mapping tool that would do that. I was hoping there was some kind of mapping tool or something that could do that where we didn't have to hire it done but oh well. Thanks! I do appreciate the responses.

            Comment


              #7
              I don't really understand your question/need. But, it sounds like you want/need an XML editor?? Check out http://www.oxygenxml.com/download which includes a Linux version. Yes, it isn't free, but it does have a trial license key so you can try it.
              Using Kubuntu Linux since March 23, 2007
              "It is a capital mistake to theorize before one has data." - Sherlock Holmes

              Comment


                #8
                XML editor yes but one that can be automated. A mapping software more than anything. Though I can say this part of OxygenXML intrigues me --> XML diff and merge. Thanks!

                Comment


                  #9
                  Hmmmm... That was very close to what I was thinking. I'll have to Trial it and just see what it can actually do. I don't think quite what I want but still seems to be a very well put together editor. Again, Thanks!

                  Comment


                    #10
                    You may then, want to look at jaxml -- http://www.librelogiciel.com/softwar...n_Presentation
                    Using Kubuntu Linux since March 23, 2007
                    "It is a capital mistake to theorize before one has data." - Sherlock Holmes

                    Comment


                      #11
                      Hmmmmmm. Will take a look see. Again, thanks!

                      Comment


                        #12
                        The following little script reads a file 'text.xml', removes all the 'D' elements (child nodes of 'C') and inserts them one at a time. After each D element is reinserted, it writes out a new xml file.

                        test.xml:
                        Code:
                        <A>
                            <B>
                                <C>
                                    <D1/>
                                    <D2/>
                                    <D3/>
                                    <D4/>
                                </C>
                            </B>
                        </A>
                        My solution uses the lxml python package:
                        Code:
                        [font=courier]
                        #! /usr/bin/env python
                        
                        from lxml import etree
                        
                        doc = etree.parse('test.xml')
                        root = doc.getroot()
                        c = root.find('.//C')  # find node with tag 'C'
                        
                        d = c.getchildren() # get all 'D' elements
                        # delete all D elements that are children of C
                        for i in range(len(d)):
                            c.remove(d[i])
                        
                        # Now add them in 1 at a time and save at each iteration
                        for i in range(len(d)):
                            c.append(d[i])
                            doc.write('file%d.xml' % i+1, pretty_print=True)
                            # delete what was just added.
                            c.remove(d[i])[/font]
                        Hope this helps.

                        Comment


                          #13
                          Cool!!!!! Thanks! I will look at this today.

                          Comment


                            #14
                            Sorry for the delay on this. Our EDI VAN actually has this solved BUT very similar to the above. A bit more fancy on their end. Nice software they have. I was at least able to help and see their software mapping tool in action. Anyway I still tried the code you provided. Had to make a slight change on the DOC.WRITE. %i+1 needed to be %(i+1). So, the issue now with it is this based on my test XML. Lets say NODE C has 5 CHILDREN NODES (D). The code actually produces 22 files and only the last 5 are the mostly correct ones. There are a few missing closes on some entries. Could the "pretty_print" be doing that? Anyway, this was real close to what I was wanting and for my own purposes I'm looking further into this as this will be of great value! Thanks! Much, Much Thanks!

                            Comment


                              #15
                              OK. I see what is going on. I need to read up on Python and the lxml module but this is very encouraging and will finally force me to learn Python which I've been trying to do for a while.



                              EDIT: Done! That works exactly what I was wanting. Now I have my alternatives if something like this arises again which I think it will. Thanks! andystmartin!
                              Last edited by MoonRise; Dec 06, 2013, 01:02 PM.

                              Comment

                              Working...
                              X