Simple XML Framework - Adding XSI Location in JAVA

2019-06-14 09:49发布

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条回答
迷人小祖宗
2楼-- · 2019-06-14 10:18

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.

查看更多
登录 后发表回答