Regular views
The content of the root element needs to be captured <pubDate>
, but in a document it can be either inside the element <item>
or inside the element <channel>
. Also <item>
is a child <channel>
I will give an example
<channel>
...
<pubDate>10/2/2010</pubDate>
...
<item>
...
<pubDate>13/2/2029</pubDate>
...
</item>
...
</channel>
must be fixed on 10/2/2010
If the problem <item>
cannot be resolved, it can be recorded along with it <pubDate>
.
a source to share
I don't know JavaScript, so I can't help you with the DOM. I agree 100% that it is a bad idea to try and parse XML with regex. However, there can be a quick, very messy and very fragile workaround:
If the indentation is consistent throughout the file, and the elements are <channel>
always at the same indentation level, you can use that fact as a guide to the regexp. In your example /^ {2}<pubDate>([^<]*)<\/pubdate>/m
(= two spaces after the start of the line) might just work.
Use this at your own risk. There will be dragons, etc.
a source to share
Check out jQuery and see if it helps reading / parsing XML: http://think2loud.com/reading-xml-with-jquery/
KM
a source to share