Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Making a script to parse simple XML and send it to variables.


    I'm trying to pass a variable to sed that contains XML.

    From this XML I would like to extract the parts contained between <image_viewer> </image_viewer> ; and <image_thumb_url> </image_thumb_url>

    There is an HTML link between each of those tags, which has no spaces; and each tags + link are on a single line.

    It seems I'm doining it completely wrong, I'm very new to bash...

    base64 -w0 "$1" > "$1".64.jpg
    apiXml=$(curl -v -F "upload=<$1.64.jpg" -F key="$apiKey" -F format=xml "$apiUrl")
    imgView=$(echo "$apiXml" | sed 's/<image_viewer>\(.*\)<\/image_viewer>/\1/')
    imgThumb=$(echo "$apiXml" | sed 's/<image_thumb_url>\(.*\)<\/image_thumb_url>/\1/')
    Everything works up to the imgView=... part, anyone has an idea about this ?


  2. #2
    that code works for me.

    1. post the contents of $apiXml

    2. is sed spitting out any errors?

  3. #3
    Just Joined!
    Join Date
    Apr 2005
    Helsinki, Finland
    Funny question, why use sed for querying information from xml document!?
    Why not use of other tools!?

    so you just need a value from some xml file..right?! Why not something like..

    #! /bin/bash
     imgView=$(/usr/bin/xmllint --xpath "root/picture/imageView/text()" ${apiXML})
    imgThumb=$(/usr/bin/xmllint --xpath "root/pics/image_thumb_url/text()" ${apiXML} )
    echo "$imgView"
    echo "$imgThumb"
    in case the path of the xml might change then you could simply do
    xmllint --xpath "//imageView/text()"  ${apiXML}
    Hope this helps..

    Kind Regards,
    Noel Alex Makumuli

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts