Chunk by Chunk processing of XML

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rellaboyina
    New Member
    • Jan 2007
    • 55

    Chunk by Chunk processing of XML

    Need to process an XML Chunk by Chunk.....

    I had an XML. It will consist of a number of similar type of tags and what I want to do is to process a certaing group of methods on each of these similar group of tags everytime.

    I tried it out with XML::Twig. But not able to get it as I am new to Perl.

    Can anybody help me out in this please.....

    Eg:
    <tsip:dataFeed= ....>
    <tsip><inventio n>.....</invention></tsip>
    <tsip><inventio n>.....</invention></tsip>
    <tsip><inventio n>.....</invention></tsip>
    </tsip:dataFeed>

    Now what I want to do is , to process each <tsip></tsip> element using some methods which are user-defined.
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    Do you have this same question on another forum? Has it recieved any replies if you do?

    Comment

    • docsnyder
      New Member
      • Dec 2006
      • 88

      #3
      @rellaboyina

      Try something like this:

      Code:
      $tag = "tsip";
      
      @lines = (
        "<tsip:dataFeed=....>",
        "<tsip><invention>.....</invention></tsip>",
        "<tsip><invention>.....</invention></tsip>",
        "<tsip><invention>.....</invention></tsip>",
        "</tsip:dataFeed>",
      );
      
      sub userDefinedMethod {
        my($content) = @_;
      
        printf("$content\n");
      }
      
      for $line ( @lines ) {
        if ( $line =~ m(^<$tag>(.*)</$tag>$) ) {
          userDefinedMethod($1);
        }
      }
      Greetz, Doc

      Comment

      • rellaboyina
        New Member
        • Jan 2007
        • 55

        #4
        Originally posted by KevinADC
        Do you have this same question on another forum? Has it recieved any replies if you do?
        Till now I haven't recieved any replies for this query. Can u help me out please?

        Comment

        • KevinADC
          Recognized Expert Specialist
          • Jan 2007
          • 4092

          #5
          did you read the suggestion posted by doc?

          Comment

          • rellaboyina
            New Member
            • Jan 2007
            • 55

            #6
            I have tried with what Mr.doc has suggested. But it will not fulfill my purpose.

            For that what I was doing is, I have taken the module XML::Twig, and parsing the file using the xpaths of the required tags, attributes and the elements.

            But to process each <tsip> what I was doing is that, creating a separate xml file for each tsip and parsing that which will ultimately result in the more memory consumption.

            So I would like to know that whether there is any process of parsing the xml file without following the process which I did and taking the less memory.

            Comment

            • KevinADC
              Recognized Expert Specialist
              • Jan 2007
              • 4092

              #7
              I'm sure there is but it's something I have no practical experience with. There are a lot of XML modules, maybe one of the other ones will work for you:

              XML::XPath or XML::LibXML

              Comment

              • rellaboyina
                New Member
                • Jan 2007
                • 55

                #8
                I have already tried with XML::XPath. But the module XML::Twig is giving the best performance when compared to XML::XPath. So can you please help me out in this?

                Comment

                Working...