You might also look into the command-line tool XMLStarlet. It can be installed on macOS using Homebrew. I playing with it for 15 minutes and here’s what I came up with for extracting data from your example:

`xml sel -t -m '//field' -v 'name(*[1])' -o $'\t' -v '*[1]' -o $'\t' -v 'value' -o $'\n' example.xml`

Output is:

```
key1    NAME    John Appleseed
key2    Company Google
```

Documentation here: http://xmlstar.sourceforge.net/doc/UG/

Hope this helps.
-sam

On 25 Feb 2020, at 3:24, Gustave Stresen-Reuter wrote:

Have you looked into xslt? That's really the tool you should be using for xml transformations. The learning curve is steep-ish but this is the exact
use case it was designed for.

Have a look. The Mac confess with a command line tool called xsltproc
preinstalled that is normally more than sufficient for the types of
transformations. I usually pipe the output to bbedit for verification of my
work when the transformation is complete.

Ted

On Mon, Feb 24, 2020, 6:50 PM Miguel Perez <maperezespin...@gmail.com>
wrote:

This could be an option too. Thank you.
Excel ended up not working in this case because while it reads the file,
it has a weird formatting too and I cannot work with it much better.
The formula posted above works much better for me and is what I was
looking for.

El lunes, 24 de febrero de 2020, 12:12:16 (UTC-6), ThePorgie escribió:

One other thing about a xml tool. The latest version of Mac Excel will
now open xml. Just an fyi if that would work to get the names you're
looking for.



On Monday, February 24, 2020 at 11:44:36 AM UTC-5, Miguel Perez wrote:

Hi,

I'm fairly new to RegEx and I need your help.

I process many XML files in my job. Most of them are formatted
correctly, that is:
<key1>Value</key1>
<key2>Value</key2>

For those I search for values using:

<key1>.*?</key1>
And it works like a charm.

But then I have this one source that formats its XML files with CDATA
fields like this:
<field>
    <key><![CDATA[NAME]]></key>
    <value><![CDATA[John Appleseed]]></value>
</field>
In this example they are trying to say that the value *NAME* is *John Appleseed*. Rather than putting it as a key/value pair, they do that
weird syntax.

What GREP pattern can I use to extract all the names for this formatting?

I am open to other solutions, like BASH scripts and Applescript. I'm
desperate.

Thank you for your help, friends.

🙂

--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "supp...@barebones.com"
rather than posting here. Follow @bbedit on Twitter: <
https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/bbedit/4bab3829-303a-4b88-ab22-fca5baa527f9%40googlegroups.com
<https://groups.google.com/d/msgid/bbedit/4bab3829-303a-4b88-ab22-fca5baa527f9%40googlegroups.com?utm_medium=email&utm_source=footer>
.


--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "supp...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/CAKAQjiegKT8R_iHB16Scv_E-4R%3DbpN8riZYc_-zFuGNLgTN48Q%40mail.gmail.com.


--
This is the BBEdit Talk public discussion group. If you have a feature request or need 
technical support, please email "supp...@barebones.com" rather than posting here. 
Follow @bbedit on Twitter: <https://twitter.com/bbedit>
--- You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/D91728B6-7B69-47BA-B2DF-6DB108888668%40munkynet.org.

Reply via email to