<key1>Value</key1>
<key2>Value</key2>
<key1>.*?</key1>
<field> <key><![CDATA[NAME]]></key> <value><![CDATA[John Appleseed]]></value></field><field>
<key1><![CDATA[NAME]]></key1>
<value><![CDATA[John Appleseed]]></value>
</field>
<field>
<key2><![CDATA[Company]]></key2>
<value><![CDATA[Google]]></value>
</field>Can you give us a real-world example? I’m not clear on whether “key1” and “key2” literally appear in your document or if they are placeholders.
In any case, you should probably use a tool that is designed to work with XML. Such a tool would take care of the CDATA sections for you and let you search for things in a hierarchical way.
You might be able to “get the job done” with text-oriented tools, but it will eventually drive you insane.
-sam
--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@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+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/8c4b1b3f-c421-472f-967f-9e3d5d3dfff8%40googlegroups.com.
Thank you, ThePorgie.Unfortunately it doesn't work for me.I should've said that there are many values using this syntax, like this:<field>
<key1><![CDATA[NAME]]></key1>
<value><![CDATA[John Appleseed]]></value>
</field>
<field>
<key2><![CDATA[Company]]></key2>
<value><![CDATA[Google]]></value>
</field>As you can see, there are two keys, but the very next line says value for both of them. That is my main concern.I want value1 for each item on the list, but its defining key is in the line above with that CDATA formatting.Any ideas?
--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@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+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/4bab3829-303a-4b88-ab22-fca5baa527f9%40googlegroups.com.
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
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/CAKAQjiegKT8R_iHB16Scv_E-4R%3DbpN8riZYc_-zFuGNLgTN48Q%40mail.gmail.com.