سؤال

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?

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

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=\").*(?=\")
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top