문제

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