Domanda

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?

È stato utile?

Soluzione

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

Altri suggerimenti

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=\").*(?=\")
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top