How can I extract XML from a text document?

I have tons of text documents containing useless text and a section of XML. I would like to use either Mac Automator or Apple Script to pull the XML section out and place it in a new document with a .xml extension. How can I do that?
Here is a sample of the XML section that I need to pull:
- ---Start ACNS XML
<?xml version="1.0" encoding="UTF-8"?>
<Infringement xsi:schemaLocation="http://www.movielabs.com/ACNS/ACNS2v1.xsd" xmlns="http://www.movielabs.com/ACNS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">           <Case>
<ID>22242387629</ID>
<Status>OPEN</Status>
<Severity>Normal</Severity>
</Case>
<Complainant>
<Entity>MPAA Search and Notify</Entity>
<Contact></Contact>
<Address></Address>
<Phone>5555555555</Phone>
<Email>[email protected]</Email>
</Complainant>
<Service_Provider>
<Entity>Some Place, Somewhere</Entity>
<Contact></Contact>
<Address>Some Place, Somewhere  </Address>
<Phone></Phone>
<Email>[email protected]</Email>
</Service_Provider>
<Source>
<TimeStamp>2011-12-02T23:41:59.94Z</TimeStamp>
<IP_Address>127.0.0.1</IP_Address>
<Port>64153</Port>
<Type>P2P</Type>
<SubType BaseType="P2P" Protocol="BitTorrent" />
<UserName></UserName>
<Number_Files>1</Number_Files>
</Source>
<Content>
<Item>
<TimeStamp>2011-12-02T23:41:59.94Z</TimeStamp>
<AlsoSeen Start="2011-12-02T23:40:00.11Z" End="2011-12-02T23:41:59.94Z"></AlsoSeen>
<Title>asdfasdf (2011)</Title>
<Artist></Artist>
<FileName>asdfasdf (2011) DVDRip XviD-MAXSPEED</FileName>
<FileSize>1580908467</FileSize>
<Type>Video</Type>
<Hash Type="SHA1">8FB7B1F4984AB6E0746B43D2B82D4ED8102984D5</Hash>
</Item>
</Content>
<History></History>
<Notes></Notes><Type Retraction="false">DMCA</Type>
<Detection>
<Asset>
<OriginalAssetName>asdfasdf (2011)</OriginalAssetName>
</Asset>
<ContentMatched Audio="false" Video="true" Text="false" />
<HashMatched>true</HashMatched>
<VerificationID>Manual and automated watermark verification</VerificationID>
</Detection>
<Verification>
<VerificationLevel Type="DT">2</VerificationLevel>
</Verification>
<TextNotice><![CDATA[12-03-2011

XML portion always starts with <Infringement and ends with </Infringement>.
Actually, it doesn't... the XML starts with the <?xml> tag, but that's just me being pedantic
Given what you've said, though, it's easy to extract the XML data from a given block of text.
First, read the source data:
set theText to read file "path:to:the:file"
Then you can extract the XML via something like:
set start_tag to "<?xml"
set end_tag to "</Infringement>"
set start_of_data to offset of start_tag in theText
set end_of_data to (offset of end_tag in theText) + (-1 + (length of end_tag))
set theXML to text start_of_data through end_of_data of theText
Now you can write that data to a file:
set theFile to open for access file ((path to desktop as text) & "output.xml" as text) with write permission
set eof theFile to 0
write theXML to theFile starting at 0
close access theFile
If you have multiple files you can either run this in a loop that iterates over the files, or save the script as a droplet, then drop the files onto the script icon. Let me know if you need help with that, too.

Similar Messages

  • How Can I extract pages from a PDF document into a separate document by clicking a link?

    Hi,
    I have created a large PDF document with several pages, I have a link symbol on the contents page of the document that relates to several services on different pages within the document. Currently they are identified by having the same link symbol on every page that relates to that particular service. I was wondering if there was any way in which I can create a interactive pdf, when I click the initial symbol link on the contents, it collates all the relevant linked service pages into a single document or guides the viewer to all the pages without having to create a separate pdf document for each service?
    Many thanks
    Yunus

    Simple answer - no. PDF files cannot reassemble themselves into new documents, nor can you hide pages.

  • How can i extract data from oracle table  to flat file or excel spread shee

    Hello,
    DB Version is 10.1.0.3.0
    How can i extract data from oracle table to flat file or excel spread sheet by using sub programs?
    Regards,
    D

    Here what I did
    SET NEWPAGE 0
    SET SPACE 0
    SET LINESIZE 80
    SET PAGESIZE 0
    SET ECHO OFF
    SET FEEDBACK OFF
    SET VERIFY OFF
    SET HEADING OFF
    SET MARKUP HTML OFF SPOOL OFF
    Sql> SPOOL bing
    select * from -------;
    SPOOL OFF;
    I do not see file.
    I also tried
    Sql> SPOOL /tmp/bing
    select * from -------;
    SPOOL OFF;
    But still not seeing the fie,

  • How can I extract image from complex (multycoloured0 background?

    How can I extract image from complex (multycoloured) shot?

    I would say either using the pen tool or the quick mask tool but without seeing how complex the image/background is I can't give you a complete answer...?
    Can you post the image?

  • How can I extract photos from my backup (5000+ photos) for free?

    How can I extract photos from my backup (5000+  photos) for free?

    eyal123 wrote:
    How can I extract photos from my backup (5000+  photos) for free?
    You cannot.
    Why are you opposed to paying for some software to help do what you want?
    You can restore the backup to your iPhone then sync the photos to your computer.

  • How can i extract attributes from XML-file

    Hi!
    I want to extract XML-files.
    And the most tags are no problem,but how can i extract attributes?
    Here is a part from the XML-Schema:
    <xs:complexType name="ATT_LIST">
              <xs:sequence>
                   <xs:element name="ATTRIB" minOccurs="0" maxOccurs="unbounded">
                        <xs:complexType>
                             <xs:sequence>
                                  <xs:element name="VALUE"/>
                             </xs:sequence>
                             <xs:attribute name="ATTNAM" use="required"/>
                        </xs:complexType>
                   </xs:element>
              </xs:sequence>
         </xs:complexType>
    Thanks for help.
    With best regards.
    Nicole

    Hi!
    If i delete one '/' i get the error message:
    data can't be found'
    This is my xml-file:
    <?xml version="1.0" encoding="UTF-8"?>
    <INSOBJ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sv6:8080/sys/schemas/SCOTT/sv6:8080/public/mydocs/inspection_pda_schema.xsd">
         <INSP_PDA>
              <SYSID>900000438</SYSID>
              <INSPECTOR/>
              <INSDAT>20001223</INSDAT>
              <INSOBJ_TYP>MSP-Mast</INSOBJ_TYP>
              <INSOBJ_ID1>BAM / Bad Aussee / Bad Mitterndorf/Grundlsee</INSOBJ_ID1>
              <INSOBJ_ID2>MITTERNDORF 2 - M 259</INSOBJ_ID2>
              <INSOBJ_ID3>239</INSOBJ_ID3>
              <INSOBJ_NAME>259</INSOBJ_NAME>
              <PDA_PORTION>0000000391</PDA_PORTION>
              <GESQUALITAET/>
              <AUSFALLSEINSCH/>
              <ANMERKUNGEN/>
              <LAGE_NORD>48,2281993</LAGE_NORD>
              <LAGE_OST>14,2394658</LAGE_OST>
              <HOEHE/>
              <GPS_STATUS/>
              <KOORD_SYSTEM/>
              <KOORD_EINHEIT/>
              <PLZ/>
              <ORT/>
              <STR_ORTSTEIL/>
              <NUMMER/>
              <BEZEICHNUNG/>
              <GRUNDBESITZER/>
              <TELENR/>
              <ERREICHBARKEIT/>
              <ATT_LIST>
                   <ATTRIB ATTNAM="BAUWEISE">
                        <VALUE>E-Mast</VALUE>
                   </ATTRIB>
                   <ATTRIB ATTNAM="HOLZART">
                        <VALUE>KIEFER</VALUE>
                   </ATTRIB>
              </ATT_LIST>
              <MZ_LIST>
                   <MAS_ZU MZ_NAM="AUSHOLZEN">
                        <VALUE>J</VALUE>
                        <BEMERKUNG/>
                        <INSP_AM/>
                        <INSP_VON/>
                        <DONE_AM>N</DONE_AM>
                        <DONE_VOM/>
                        <URSACHE>2</URSACHE>
                        <DRINGLICH>2</DRINGLICH>
                        <ZIEL_DAT/>
                        <MZ_PARAM_LIST/>
                   </MAS_ZU>
                   <MAS_ZU MZ_NAM="ALLGEMEIN-ANMERKUNG">
                        <VALUE>2 Isolatoren</VALUE>
                        <BEMERKUNG/>
                        <INSP_AM/>
                        <INSP_VON/>
                        <DONE_AM/>
                        <DONE_VOM/>
                        <URSACHE>2</URSACHE>
                        <DRINGLICH/>
                        <ZIEL_DAT/>
                        <MZ_PARAM_LIST/>
                   </MAS_ZU>
                   <MAS_ZU MZ_NAM="Stange erdfaul/hohl">
                        <VALUE>J</VALUE>
                        <BEMERKUNG/>
                        <INSP_AM/>
                        <INSP_VON/>
                        <DONE_AM/>
                        <DONE_VOM/>
                        <URSACHE/>
                        <DRINGLICH/>
                        <ZIEL_DAT/>
                        <MZ_PARAM_LIST/>
                   </MAS_ZU>
                   <MAS_ZU MZ_NAM="Masttyp nicht normgerecht">
                        <VALUE>J</VALUE>
                        <BEMERKUNG/>
                        <INSP_AM/>
                        <INSP_VON/>
                        <DONE_AM/>
                        <DONE_VOM/>
                        <URSACHE/>
                        <DRINGLICH/>
                        <ZIEL_DAT/>
                        <MZ_PARAM_LIST/>
                   </MAS_ZU>
              </MZ_LIST>
         </INSP_PDA>
         <INSP_PDA>
              <SYSID>900000437</SYSID>
              <INSPECTOR/>
              <INSDAT>20001223</INSDAT>
              <INSOBJ_TYP>MSP-Mast</INSOBJ_TYP>
              <INSOBJ_ID1>BAM / Bad Aussee / Bad Mitterndorf/Grundlsee</INSOBJ_ID1>
              <INSOBJ_ID2>MITTERNDORF 2 - M 259</INSOBJ_ID2>
              <INSOBJ_ID3>239</INSOBJ_ID3>
              <INSOBJ_NAME>259</INSOBJ_NAME>
              <PDA_PORTION>0000000391</PDA_PORTION>
              <GESQUALITAET/>
              <AUSFALLSEINSCH/>
              <ANMERKUNGEN/>
              <LAGE_NORD>48,2281993</LAGE_NORD>
              <LAGE_OST>14,2394658</LAGE_OST>
              <HOEHE/>
              <GPS_STATUS/>
              <KOORD_SYSTEM/>
              <KOORD_EINHEIT/>
              <PLZ/>
              <ORT/>
              <STR_ORTSTEIL/>
              <NUMMER/>
              <BEZEICHNUNG/>
              <GRUNDBESITZER/>
              <TELENR/>
              <ERREICHBARKEIT/>
              <ATT_LIST>
                   <ATTRIB ATTNAM="BAUWEISE">
                        <VALUE>E-Mast</VALUE>
                   </ATTRIB>
                   <ATTRIB ATTNAM="HOLZART">
                        <VALUE>KIEFER</VALUE>
                   </ATTRIB>
              </ATT_LIST>
              <MZ_LIST>
                   <MAS_ZU MZ_NAM="AUSHOLZEN">
                        <VALUE>J</VALUE>
                        <BEMERKUNG/>
                        <INSP_AM/>
                        <INSP_VON/>
                        <DONE_AM>N</DONE_AM>
                        <DONE_VOM/>
                        <URSACHE>2</URSACHE>
                        <DRINGLICH>2</DRINGLICH>
                        <ZIEL_DAT/>
                        <MZ_PARAM_LIST/>
                   </MAS_ZU>
                   <MAS_ZU MZ_NAM="ALLGEMEIN-ANMERKUNG">
                        <VALUE>2 Isolatoren</VALUE>
                        <BEMERKUNG/>
                        <INSP_AM/>
                        <INSP_VON/>
                        <DONE_AM/>
                        <DONE_VOM/>
                        <URSACHE>2</URSACHE>
                        <DRINGLICH/>
                        <ZIEL_DAT/>
                        <MZ_PARAM_LIST/>
                   </MAS_ZU>
                   <MAS_ZU MZ_NAM="Stange erdfaul/hohl">
                        <VALUE>J</VALUE>
                        <BEMERKUNG/>
                        <INSP_AM/>
                        <INSP_VON/>
                        <DONE_AM/>
                        <DONE_VOM/>
                        <URSACHE/>
                        <DRINGLICH/>
                        <ZIEL_DAT/>
                        <MZ_PARAM_LIST/>
                   </MAS_ZU>
                   <MAS_ZU MZ_NAM="Masttyp nicht normgerecht">
                        <VALUE>J</VALUE>
                        <BEMERKUNG/>
                        <INSP_AM/>
                        <INSP_VON/>
                        <DONE_AM/>
                        <DONE_VOM/>
                        <URSACHE/>
                        <DRINGLICH/>
                        <ZIEL_DAT/>
                        <MZ_PARAM_LIST/>
                   </MAS_ZU>
              </MZ_LIST>
         </INSP_PDA>
    </INSOBJ>
    Thanks for help.
    With best regards
    Nicole

  • BootCamp driver won´t work on my MacBook. How can I extract it from DVD?

    Hi folks.
    I´m new on BootCamp.
    After installing Windows XP SPII, witch works fine for me, I tryed to install the BootCam drivers.
    But: The Leopard DVD won´t start - like in the manual How can I extract the Drivers from the
    Leopard DVD to copy them to the BootCam partition to install them manually?
    Thank you al lot!

    It is a known problem on Microsoft's end.
    From their site:
    "SYMPTOMS
    Microsoft Windows XP Service Pack 2 (SP2) cannot read DVD-RW disks that use the Universal Disk Format (UDF) 2.00 defect management system. When you view the DVD contents by using Windows Explorer, you see an empty... ...A supported hotfix is now available from Microsoft. However, this hotfix is intended to correct only the problem that is described in this article. Apply this hotfix only to systems that are experiencing this specific problem. This hotfix might receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next service pack that contains this hotfix.
    To resolve this problem, submit a request to Microsoft Online Customer Services to obtain the hotfix. To submit an online request to obtain the hotfix, visit the following Microsoft Web site:
    http://go.microsoft.com/?linkid=6294451"
    I posted this in reply to another thread:
    "It is a known Microsoft issue with UDF in some SP2 versions, and there is a hotfix for it.
    search for this in Google:
    "DVD-RW disks appear to be empty" hotfix
    You can do it 3 ways:
    1) If you run the Xp updater (which may take hours) and follow all the instructions, reboot and run the updater again... and again until all the updates are there, then you will get the fix.
    2) Find , download and install just the hotfix... it may take some looking...
    3) contact Microsoft from their site and get the hotfix from them. "

  • How can I extract images from Numbers?

    Sounds a bit stupid but how do you extract images from Apples 'Numbers 3' on a Mac?  I have a client that sends images in XLS files, that normally in Word I would Alt Click and 'save as...'
    I was trying to stop using Word but this simple little feature will make all the difference.
    Can anyone point me in the right direction.
    Thanks,
    Dave

    Hi Wayne,
    Thank you for your response.  Sadly if you do this it copies in to the MACs clipboard as a snap shot of the image at the dimensions in Numbers.
    Eg. 
    An image I've extracted from the document via Excel saved out at it's original dimensions 1024 x 300px, even though it was placed, then scaled down to 300px wide on the sheet.
    Same image copied then pasted in to an image editor (as I couldn't paste into finder) was only 300px wide.
    The feature I need is to be able to save out the original image placed in the Numbers sheet.
    Anyone with ideas on this?

  • How can i extract messages from icloud backup in apple 4

    how can i extract watsapp messages from icloud backup in apple 4

    When you backup messages in iCloud, your SMS will be stored in Network. As i know, you cannot view the SMS. But you can try to sync to your iPhone or backup in iTunes. After that, you can extract your messages from iTunes with iPhone backup Extractor apps.

  • How can I extract images from a keynote presentation?

    Keynote itself sometimes provides images - for example, the cover of a book in the Leather Book theme. How can I extract this image in order to manipulate it? I saw an answer that seemed to help, which was to ensure that the keynote file was saved as a package - but there doesn't seem a way to make this happen with an existing presentation, since there is no 'Save As' any more and duplication doesn't seem to hack it. I'm using MacOS Lion 10.7.5.
    TIA

    I found a solution. In the Format area, select the "Image" tab. You should see the file name there. Click and hold the name and drag and drop it to your desktop (or anywhere else you want to save it). It worked perfectly for me. Hope it helps!

  • How can I extract pictures from a backup

    I update an iPhone 4 to iOS 7 and it's 16gb The iPhone that was completely out dated running iOS 4 so I updated it and backed it up but now iOS 7 takes up more of the storage and now I can't restore the backup but it's only the pictures this guy wants for his iPhone so how can I extract them?

    Restore the device using the backup.  Backups are only designed for use in restoring a device.
    If used as designed, pictures would have regularly been copied off the device to the computer for safe keeping.

  • How can I plott data from a text file in the same way as a media player using the pointer slide to go back and fort in my file?

    I would like to plott data from a text file in the same way as a media player does from a video file. I’m not sure how to create the pointer slide function. The vi could look something like the attached jpg.
    Please, can some one help me?
    Martin
    Attachments:
    Plotting from a text file like a media player example.jpg ‏61 KB

    HI Martin,
    i am not realy sure what you want!?!?
    i think you want to display only a part of the values you read from XYZ
    so what you can do:
    write all the values in an array.
    the size of the array is the max. value of the slide bar
    now you can select a part of the array (e.g. values from 100 to 200) and display this with a graph
    the other option is to use the history function of the graphes
    regards
    timo

  • How can I extract pages from a PDF? The Tools menu is missing.

    I used to be able to extract pages from my PDF file. I don't see the tools icon anymore. How can I access the tools icon?

    Hi lenm,
    To extract pages, you need to use Acrobat (not Adobe Reader). As I can attest (because I do have both Reader and Acrobat installed on the same computer), it is quite easy to open files in Reader when you mean to open then in Acrobat. So, please make sure you have the right app open. (I pull this one all the time!)
    Now, if the Tools menu is missing from Acrobat, choose View > Show/Hide > Toolbar Items > Show Toolbars to make them reappear.
    Please let us know how it goes.
    Best,
    Sara

  • How can I extract vocals from a track to use as an acapella?

    Hi, just as the title suggests I would like to know how to extract vocals from a song so I can then use it as an acapella using Audition CS5?
    Also whilst I'm here, again using audition CS5, how can I determine the bpm of whatever sound file I have open, and furthermore how can I then match the bpm from another sound file to match the bpm of the track I'm working on?
    Thanks for your time
    Dan

    Your success with isolating vocals from a song depends almost entirely on how the song was mixed, and will vary greatly.  There is no perfect solution, though many times the artifacts that remain can be minimized within a mix.  Generally, you'll have the best success with music where the vocals are panned to a specific location in the mix - usually dead center, but the tool can be used to isolate any position in the stereo field - without too much instrumentation spreading into this area.  Bass sounds are usually mixed center as well, so you may need to to some additional EQ or Spectral removal of low frequencies after you complete the extraction step.
    The tool you'll want to use in Audition is the Center Channel Extractor effect, located under the Effects > Stereo Imagery menu.  Start with the Acapella preset, then change the Extract parameter to Custom for some additional control.  Select the region you wish to isolate (it's often better to isolate passages separately as, for example, verses can be mixed very differently from a chorus) and begin playback with the effect open.  Use the Power button to temporarily bypass the effect so you can note the differences. 
    Adjust the Phase Angle and Pan parameters to maximize the vocals while minimizing the instrumentation.  Use the Frequency Range parameters to help reduce some of the low-end and high-end mix that is not associated with the vocals.  The two vertical controls on the right allow you to adjust the levels of what's being isolated vs. everything else. (Flip-Flop these to make a Karaoke mix.)  Under the Discrimination tab, the most important parameters will be the Crossover Bleed and Phase Discrimination controls.  You can adjust the FFT parameters under the Advanced tab, though I wouldn't recommend it until you're comfortable with the tool.  You don't necessarily need to know exactly what ever parameter does, but listen closely while you make adjustments and you'll begin to understand how each parameter affects the result.

  • How can I extract metadata from file names?

    If I want to extract metadata from file names? How can I do that? I want to read through the file names and when I get to a certain character ("-"), I can take the string just before that character and store it in a column in SharePoint. Is this
    do-able through scripting? 

    If I want to extract metadata from file names? How can I do that? I want to read through the file names and when I get to a certain character ("-"), I can take the string just before that character and store it in a column in SharePoint.
    Is this do-able through scripting? 
    You should be able to leverage the split method.
    In PowerShell It would look like:
    # Gather the file name
    $file = "myawesome_filename-Month-Day-Year-Ect.doc"
    #split the file name by the "-" character
    $file = $file.split("-")
    # Use a foreach Loop to gather the individual items.
    foreach ($item in $file) {
    write-host $item
    #Outputmyawesome_filename
    Month
    Day
    Year
    Ect.doc
    # If you want to only grab the first item, you can do $file[0] <-- powershell starts counting with zero base.
    $file[0]
    #output
    myawesome_filename
    Entrepreneur, Strategic Technical Advisor, and Sr. Consulting Engineer - Strategic Services and Solutions Check out my book - Powershell 3.0 - WMI: http://amzn.to/1BnjOmo | Mastering PowerShell Coming in April 2015!

Maybe you are looking for

  • New hard drive and Windows 7 issues

    I bought a new 1 Tetra Samsung hard drive for my computer since 150GB was not enough. I did this because I need windows partitioned for school. After I installed the hard drive and inserted the Mac OS disk, it would not recognize the hard drive to in

  • In need of an expert: OpenGL and drawing simple textures

    Hello, Is anyone knowledgeable about loading sprites with an alpha channel? This is the code I am using to load my sprites. The image files were png files with an alpha channel(parts where you can see through the image). But when loading it the parts

  • Problems with BPM

    Hi, I am working in the following scenery: File->BPM->File.  For this scenery I am using the document http://weblogs.sdn.sap.com/pub/wlg/1822. [original link is broken] [original link is broken] [original link is broken] [original link is broken] [or

  • ADF Application + OAS 10.1.3, how many OC4J and JVM ?

    Hi all, We are running in Production with ADF (BC+Faces) 10.1.3 in OAS 10.1.3, with maximum 300++ users. (but not nessarily all submit request on same time) Intermittently (about two times) a week, there is time where user get hung and all request ta

  • Mac Mini 2014 Photoshop CS 2014

    Hi there guys. I've moved to a new city last week, and I don't want to move my computer from back home into here. Also i'm sick tired of windows machines to work on Photoshop, it might be weird but windows UI does not help me focus on my work, don't