Question

I have a document with many string like this:

<rdf:type rdf:resource="http://example.com"/>

where http://example.com is not a constant value, it change every time. The string must become:

<process:valueType rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI">http://example.com</process:valueType>

How can i do in java?

Was it helpful?

Solution

I solved in this way:

result = result.replaceAll("(<rdf:type rdf:resource=\"([^<]*)\"/>)", "<process:valueType rdf:datatype=\"http://www.w3.org/2001/XMLSchema#anyURI\">$2</process:valueType>");

OTHER TIPS

I would use lookbehind to find rdf:datatype and select everything other than " which is actually the end of the value, something like this:

(?<=datatype=\")[^\"]*

you can do that with lookahead to:

(?<=datatype=\").*(?=\")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top