问题
Issue: No annotation provided for adding XSI location to root. Another stackoverflow question detailed the same problem but in C#. I'm not quite sure how to covert that over to JAVA. I need to update XML in a flat file and thought of just using string manipulation to add the XSI locations but I was hoping there might be a cleaner approach.
Reference Question: C# Stackoverflow Same Issue
Sample XML:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MySample xmlns:ns0="someurl" xsi:schemaLocation="someOtherurl">
<othertag/>
</ns0:MySample>
回答1:
Since it the schemaLocation is an attribute and not a namespace you can simply parse it using @Attribute annotation.
@Attribute
private String schemaLocation;
Do not forget to declare the Namespace of the root element:
@Namespace(prefix="xsi", reference="http://www.w3.org/2001/XMLSchema-instance"),
This worked just fine for me.
来源:https://stackoverflow.com/questions/23062126/simple-xml-framework-adding-xsi-location-in-java