I was working on a 2 versions of a BPM product the older one without
support for namespaces and the newer one supporting namespaces. The
messages from external systems were with namespaces. When the old system
was called it was required to strip the namespaces. Initially we
thought of using xslt to achieve this. But then again regular expression
came to our rescue. The cute little function below can remove
namespaces from xml string
public static String removeXmlStringNamespaceAndPreamble(String xmlString) {
return xmlString.replaceAll("(<\\?[^<]*\\?>)?", ""). /* remove preamble */
replaceAll("xmlns.*?(\"|\').*?(\"|\')", "") /* remove xmlns declaration */
.replaceAll("(<)(\\w+:)(.*?>)", "$1$3") /* remove opening tag prefix */
.replaceAll("(</)(\\w+:)(.*?>)", "$1$3"); /* remove closing tags prefix */
}
Love the power of regular expression :)
Friday, June 1, 2012
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2012
(113)
-
▼
June
(15)
- Java - Task interval scheduling
- VMWare Web Service FAQs
- Javadoc
- Part 4
- Part 2
- part 1
- Part 3
- swixml
- Dynamically create Swing GUI from generic XML
- http://theskyisthelimit.se/bunker-roy-learning-fro...
- Adding fields dynamically in ASP.NET
- To access html control without runat=”server” in C...
- Call a Web service from Javascript utilizing SOAP ...
- JUnit Test Patterns
- Remove XML Name Space
-
▼
June
(15)
No comments:
Post a Comment