예를 들어 다른 스키마를 가져 오는 간단한 스키마가 있습니다. 두 번째 스키마 (urn : just : attributes, just-attributes.xsd)는 단지 속성 그룹을 정의합니다.String에 정렬 할 때 JAXB가 사용하는 네임 스페이스 접두어를 사용자 정의 할 수 있습니까?
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/MySchema"
xmlns:tns="http://www.example.org/MySchema"
elementFormDefault="qualified"
xmlns:ja="urn:just:attributes">
<import schemaLocation="just-attributes.xsd" namespace="urn:just:attributes"/>
<element name="MyElement">
<complexType>
<attributeGroup ref="ja:AttributeGroup"/>
</complexType>
</element>
</schema>
저는이 스키마에서 클래스를 생성하기 위해 Metro xjc Ant 태스크를 사용하고 있습니다. 내가 겪고있는 문제는 내가 상호 작용하고있는 써드 파티 애플리케이션이 네임 스페이스에 특유하다는 것입니다. 이 경우 String 값이 필요하므로 serialize해야합니다. 나는 이것을 위해 상용구 코드를 사용한다. 나에게
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:MyElement xmlns:ns1="urn:just:attributes" xmlns:ns2="http://www.example.org/MySchema" ns1:attrib1="1234" ns1:attrib2="5678"/>
내가 가진 문제의 라인을 따라 뭔가를 제공
private static <T> String marshal(T object) throws JAXBException{
OutputStream outputStream = new ByteArrayOutputStream();
JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass());
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.marshal(object, outputStream);
return outputStream.toString();
}
이 타사는, 그들이 이름에 따라 구문 분석하는 말을하는 것입니다 xmlns:thirdpartyns="urn:just:attributes"
같은 무언가를 기대한다는 것입니다 네임 스페이스에 주어진다. 은이 소프트웨어가 작동하려면 "thirdpartyns"가되어야합니다.
결과 문자열에서 찾기 및 바꾸기가 부족하다는 점을 알고있는 사람이 있습니까? 아마도 사용자 지정 바인딩 규칙을?
감사합니다. 이것은 매력처럼 작동합니다! –
링크가 끊어졌습니다. –
링크가 죽었습니다 ... @DaveC 그것을 확인하십시오! – basZero