472,145 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

Regex to find new line chars within XML tags?

I'm pulling back contact data from Exchange using WebDAV. The problem
is a third party app is adding random "\r\n"s within the XML data,
corrupting it.

I want to remove these, but only if they occur within the XML start or
end tags (between the "<" and the ">"), since some actual data does
have new line characters. So for:

<address \r\n>15 Pine St \r\n Suite 400</address>

I'd want to remove only the first new line.

I think regex is the way to go, but I can't get the right expression.
I've tried (?<=[<])\r\n(?=>), etc but no luck.

Can anyone help?

Many thanks,

Burt

Nov 17 '05 #1
2 1984

"Burt" <bu*******@yahoo.com> wrote in
news:11**********************@z14g2000cwz.googlegr oups.com...
I'm pulling back contact data from Exchange using WebDAV. The problem
is a third party app is adding random "\r\n"s within the XML data,
corrupting it.

I want to remove these, but only if they occur within the XML start or
end tags (between the "<" and the ">"), since some actual data does
have new line characters. So for:

<address \r\n>15 Pine St \r\n Suite 400</address>

I'd want to remove only the first new line.

I think regex is the way to go, but I can't get the right expression.
I've tried (?<=[<])\r\n(?=>), etc but no luck.


I think either of these should be enough: "(?<=<[^>]*)\r?\n", or
"\r?\n(?=[^<]*>)". In well-formed XML, I can't think of a case when you
actually need to check both ends.

(Not sure if this handles attribute strings correctly, but you should be
able to add that)

Niki
Nov 17 '05 #2
Thanks Niki, the first regex worked like a charm.

Burt

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Dean H. Saxe | last post: by
5 posts views Thread by Bill Cohagan | last post: by
2 posts views Thread by Mr.Clean | last post: by
5 posts views Thread by bluesrift | last post: by
13 posts views Thread by Chris Lieb | last post: by
17 posts views Thread by Mark | last post: by
10 posts views Thread by igor.kulkin | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.