By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,325 Members | 1,128 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,325 IT Pros & Developers. It's quick & easy.

Regex to find new line chars within XML tags?

P: n/a
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
Share this Question
Share on Google+
2 Replies

P: n/a

"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

P: n/a
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.