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?

Était-ce utile?

La 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>");

Autres conseils

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=\").*(?=\")
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top