Simple XML Framework - Adding XSI Location in JAVA

柔情痞子 提交于 2019-12-08 12:50:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!