parsing xml with grm – fetching attribute

Clovertech Forums Read Only Archives Cloverleaf Tcl Library parsing xml with grm – fetching attribute

  • Creator
    Topic
  • #50131
    Klaus Wais
    Participant

      I’m trying to parse xml data with grm and fetch the content and attribute from a tag that’s repeatable.

      Fetching the content of the 1st tag is working

      set gh [grmcreate -msg $mh xml $package $type]

      set dh [grmfetch $gh {MyType.FileName}]

      set val [datget $dh VALUE]

      but I’m lost while trying to fetch the repeated s and the attribute of e.g.

      How do I have to access the tags and attributes ?

      Thanks in advance …

    Viewing 9 reply threads
    • Author
      Replies
      • #64960
        Jim Kosloskey
        Participant

          Klaus,

          I have only played around with XML in Cloverleaf(R) but isn’t there an address path to the element with a repetition position somewhere?

          When you look at that field in the XML tester what element changes upon repetition? I think you use that entire path for the grmfetch. Then I think you need to have a while or other looping mechanism to increment the counter until you get a fetch error.

          email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

        • #64961
          Klaus Wais
          Participant

            Jim,

            I looked up the forum and there is a post that deals with repetitions (increment counter) but I hoped there is a solution to use a foreach {}.

            The real challenge is still to access the xml attribute:

            I can retrieve the content of the tag but I’ve no idea how to address an attribute.

          • #64962
            Klaus Wais
            Participant

              Jim,

              thanks for the hint to look at the XML tester …I haven’t thought about this.

              I’ll use a loop for the repeated tags.

              I have found the path to access the attribute by the XML tester.

              e.g for ;

              set gh [grmcreate -msg $mh xml $package $type]

              set dh [grmfetch $gh {MyType.FileName($idx).&Type}]

              set val [datget $dh VALUE]

              The only thing I’m wondering about is if there is a difference in retrieving the tag content. For the 1st occurance of all 3 versions of the path with grmfetch seem to work the same way.

              Any comments about the usage of the “.#text” ?

              set dh [grmfetch $gh {MyType.FileName}]

              set dh [grmfetch $gh {MyType.FileName(0)}]

              set dh [grmfetch $gh {MyType.FileName(0).#text}]

            • #64963
              Jim Kosloskey
              Participant

                Klaus,

                Here is what I would do:

                I would build an Xlate (if you don’t already have one) and reference the field in question. The Xlate tool will give you the address path along with a reference to the repetition position (you already seem to have that but it never hurts to have confirmation).

                Make sure you are getting what you want via the Xlate Testing tool.

                Then Copy the Source for the field in question from your COPY Action in the Xlate and paste it into your code or just verify the construct is the same.

                Whatever the Xlate uses to reference the field is what you would use in Grm in general.

                email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

              • #64964
                Jim Lohe
                Participant

                  Jim Kosloskey wrote:

                  Klaus,

                  Here is what I would do:

                  I would build an Xlate (if you don’t already have one) and reference the field in question. The Xlate tool will give you the address path along with a reference to the repetition position (you already seem to have that but it never hurts to have confirmation).

                  Make sure you are getting what you want via the Xlate Testing tool.

                  Then Copy the Source for the field in question from your COPY Action in the Xlate and paste it into your code or just verify the construct is the same.

                  Whatever the Xlate uses to reference the field is what you would use in Grm in general.

                  Jim K…I am doing exactly that.

                • #64965
                  Jim Kosloskey
                  Participant

                    Jim,

                    Hmmm… Just guessing here (as I said I have not done much with XML but not very impressed at this point) try enclosing your notation in curly braces like this:

                    set valPointer [grmfetch $gh {nm1:DOCUMENT_MESSAGE.nm1:document_data.&format}]

                    email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

                  • #64966
                    Jim Lohe
                    Participant

                      Jim Kosloskey wrote:

                      Jim,

                      Hmmm… Just guessing here (as I said I have not done much with XML but not very impressed at this point) try enclosing your notation in curly braces like this:

                      set valPointer [grmfetch $gh {nm1:DOCUMENT_MESSAGE.nm1:document_data.&format}]

                      Thanks for the  reply.    That has been tried unsuccessfully.   Still looking for answers.     I am not impressed either.    The reason I am trying to do this in tcl is because some of my document-embedded xml is taking 5-8 minutes to go through the xlate.   Hoping tcl is faster.    I dont need messages stuck in state 5 for that long!

                    • #64967
                      Jim Kosloskey
                      Participant

                        I should clarify it is XML with which I am not very impressed.

                        By the way what releas of Clovelreaf are you trying this on?

                        How large are these messages?

                        email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

                      • #64968
                        Jim Lohe
                        Participant

                          Jim Kosloskey wrote:

                          I should clarify it is XML with which I am not very impressed.

                          By the way what releas of Clovelreaf are you trying this on?

                          How large are these messages?

                          Me too.  Cloverleaf in general is wonderful.  

                          I figured it out, or rather a co-worker did.    When I compiled the XML the first time I didnt select a root.     I had since selected root on a subsequent compile.   That left me with two ocm files.   I was using the wrong one.    (That one did have the &format tag, but it still couldnt “see” it).

                          Thanks for your help.    Turns out it was something stupid.

                        • #64969
                          Jim Kosloskey
                          Participant

                            Ain’t it always 🙄

                            email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

                        Viewing 9 reply threads
                        • The forum ‘Tcl Library’ is closed to new topics and replies.