Beispiel #1
0
  public static void fixNamespaceForXsiType(final XmlObject object, final QName value) {
    final XmlCursor cursor = object.newCursor();
    while (cursor.hasNextToken()) {
      if (cursor.toNextToken().isStart()) {
        final String xsiType = cursor.getAttributeText(W3CConstants.QN_XSI_TYPE);
        if (xsiType != null) {

          final String[] toks = xsiType.split(":");
          String localName;
          String prefix;
          if (toks.length > 1) {
            prefix = toks[0];
            localName = toks[1];
          } else {
            localName = toks[0];
          }
          if (localName.equals(value.getLocalPart())) {
            cursor.setAttributeText(
                W3CConstants.QN_XSI_TYPE,
                Joiner.on(Constants.COLON_CHAR)
                    .join(
                        XmlHelper.getPrefixForNamespace(object, value.getNamespaceURI()),
                        value.getLocalPart()));
          }
        }
      }
    }
    cursor.dispose();
  }
Beispiel #2
0
 public static void fixNamespaceForXsiType(XmlObject content, Map<?, ?> namespaces) {
   final XmlCursor cursor = content.newCursor();
   while (cursor.hasNextToken()) {
     if (cursor.toNextToken().isStart()) {
       final String xsiType = cursor.getAttributeText(W3CConstants.QN_XSI_TYPE);
       if (xsiType != null) {
         final String[] toks = xsiType.split(":");
         if (toks.length > 1) {
           String prefix = toks[0];
           String localName = toks[1];
           String namespace = (String) namespaces.get(prefix);
           if (Strings.isNullOrEmpty(namespace)) {
             namespace = CodingRepository.getInstance().getNamespaceFor(prefix);
           }
           if (StringHelper.isNotEmpty(namespace)) {
             cursor.setAttributeText(
                 W3CConstants.QN_XSI_TYPE,
                 Joiner.on(Constants.COLON_CHAR)
                     .join(
                         XmlHelper.getPrefixForNamespace(content, (String) namespaces.get(prefix)),
                         localName));
           }
         }
       }
     }
   }
   cursor.dispose();
 }
 protected void addSchemaLocations(XmlObject xmlObject, Map<String, String> locations) {
   StringBuilder sb = new StringBuilder();
   for (Entry<String, String> entry : locations.entrySet()) {
     if (sb.length() > 0) {
       sb.append(" ");
     }
     sb.append(entry.getKey() + " " + entry.getValue());
   }
   XmlCursor cursor = xmlObject.newCursor();
   if (cursor.toFirstChild()) {
     cursor.setAttributeText(
         new QName("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation"), sb.toString());
   }
 }