Searching in lot of XML

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • m6s
    New Member
    • Aug 2007
    • 55

    Searching in lot of XML

    Hello...

    Can anyone help me on this, I have some xml and I want to find if an element, e.g. <BEER></BEER>
    contains something (what ever) while those that are empty to skip.
    I tried, the usual grep and fgrep or awk but as far as I got was to return every aspect of this element.

    Thank you.
  • radoulov
    New Member
    • Jun 2007
    • 34

    #2
    You need to provide a sample input and an example of the desired output.

    Comment

    • m6s
      New Member
      • Aug 2007
      • 55

      #3
      Originally posted by radoulov
      You need to provide a sample input and an example of the desired output.
      Code:
      <ORDER>
      <BOX>1</BOX>
      <BEER>12</BEER>
      <WINE>15</WINE>
      <BEER></BEER>
      <WINE>ERROR</WINE>
      ...
      </ORDER>
      Sth like that XML, it's very simple...as data.

      Comment

      • jeasoft
        New Member
        • Feb 2008
        • 6

        #4
        Excuse me for the question, but my english is not my best thing :P.

        Do you need to search the element in the xml file?

        If you want to search IN the file, you can you some editor and use some function to search on it.
        For example, Gedit (ctrl + f to find), or VI (in command line, /xml ---> this search and show the results).

        I ask excuses if this is not the right thing.

        Comment

        • ghostdog74
          Recognized Expert Contributor
          • Apr 2006
          • 511

          #5
          only tested on your sample
          Code:
          awk '{n=gsub(/<BEER>|<\/BEER>/,""); if(n>0) print $0}' file

          Comment

          • m6s
            New Member
            • Aug 2007
            • 55

            #6
            Originally posted by ghostdog74
            only tested on your sample
            Code:
            awk '{n=gsub(/<BEER>|<\/BEER>/,""); if(n>0) print $0}' file
            Well...It worked..!!!
            Can u give us some more details? What you wrote?

            Thank u a lot!

            Comment

            Working...