gpt4 book ai didi

com.sun.xml.bind.v2.runtime.XMLSerializer.startElement()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-23 20:05:05 25 4
gpt4 key购买 nike

本文整理了Java中com.sun.xml.bind.v2.runtime.XMLSerializer.startElement()方法的一些代码示例,展示了XMLSerializer.startElement()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLSerializer.startElement()方法的具体详情如下:
包路径:com.sun.xml.bind.v2.runtime.XMLSerializer
类名称:XMLSerializer
方法名:startElement

XMLSerializer.startElement介绍

[英]Variation of #startElement(String,String,String,Object) that forces a specific prefix. Needed to preserve the prefix when marshalling DOM.
[中]#startElement(String,String,String,Object)的变体,强制使用特定的前缀。在编组DOM时需要保留前缀。

代码示例

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

public void startElement(Name tagName, Object outerPeer) {
  startElement();
  nse.setTagName(tagName,outerPeer);
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

serializer.startElementForce(namespaceURI,localName,p,null);
else
  serializer.startElement(namespaceURI,localName, p,null);

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

public void startElement(String nsUri, String localName, String preferredPrefix, Object outerPeer) {
  startElement();
  int idx = nsContext.declareNsUri(nsUri, preferredPrefix, false);
  nse.setTagName(idx,localName,outerPeer);
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

/**
 * Variation of {@link #startElement(String, String, String, Object)} that forces
 * a specific prefix. Needed to preserve the prefix when marshalling DOM.
 */
public void startElementForce(String nsUri, String localName, String forcedPrefix, Object outerPeer) {
  startElement();
  int idx = nsContext.force(nsUri, forcedPrefix);
  nse.setTagName(idx,localName,outerPeer);
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

private void bareStartTag(XMLSerializer w, Name tagName, Object peer) throws IOException, XMLStreamException, SAXException {
  w.startElement(tagName,peer);
  w.endNamespaceDecls(peer);
  w.endAttributes();
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

public void serializeBody(Object array, XMLSerializer target) throws SAXException, IOException, XMLStreamException {
  int len = Array.getLength(array);
  for( int i=0; i<len; i++ )  {
    Object item = Array.get(array,i);
    // TODO: check the namespace URI.
    target.startElement("","item",null,null);
    if(item==null) {
      target.writeXsiNilTrue();
    } else {
      target.childAsXsiType(item,"arrayItem",itemBeanInfo, false);
    }
    target.endElement();
  }
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

public void marshal(T value, XMLSerializer out) throws IOException, SAXException, XMLStreamException {
  out.startElement(tagName,null);
  if(value==null) {
    out.writeXsiNilTrue();
  } else {
    out.childAsXsiType(value,null,bi,false);
  }
  out.endElement();
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

w.startElement(typeNames.values().iterator().next().tagName,null);
  w.childAsXsiType(v,fieldName,w.grammar.getBeanInfo(Object.class), addNilDecl && nillable);
} else {
  w.startElement(tt.tagName,null);
  w.childAsXsiType(v,fieldName,tt.beanInfo, addNilDecl && nillable);
w.startElement(nullTagName,null);
w.writeXsiNilTrue();
w.endElement();

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

public final void serializeRoot(BeanT bean, XMLSerializer target) throws SAXException, IOException, XMLStreamException {
  if(tagName==null) {
    target.reportError(
      new ValidationEventImpl(
        ValidationEvent.ERROR,
        Messages.UNABLE_TO_MARSHAL_NON_ELEMENT.format(bean.getClass().getName()),
        null,
        null));
  }
  else {
    target.startElement(tagName,bean);
    target.childAsSoleContent(bean,null);
    target.endElement();
  }
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

public void serializeRoot(BeanT bean, XMLSerializer target) throws SAXException, IOException, XMLStreamException {
  if(tagName==null) {
    Class beanClass = bean.getClass();
    String message;
    if (beanClass.isAnnotationPresent(XmlRootElement.class)) {
      message = Messages.UNABLE_TO_MARSHAL_UNBOUND_CLASS.format(beanClass.getName());
    } else {
      message = Messages.UNABLE_TO_MARSHAL_NON_ELEMENT.format(beanClass.getName());
    }
    target.reportError(new ValidationEventImpl(ValidationEvent.ERROR,message,null, null));
  } else {
    target.startElement(tagName,bean);
    target.childAsSoleContent(bean,null);
    target.endElement();
    if (retainPropertyInfo) {
      target.currentProperty.remove();
    }
  }
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

w.startElement(typeMap.values().iterator().next().tagName,null);
    w.childAsXsiType(item,fieldName,w.grammar.getBeanInfo(Object.class), false);
  } else {
    w.startElement(tt.tagName,null);
    serializeItem(tt.beanInfo,item,w);
} else {
  if(nillableTagName!=null) {
    w.startElement(nillableTagName,null);
    w.writeXsiNilTrue();
    w.endElement();

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

@Override
public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException {
  ValueT v = acc.get(o);
  if(v!=null) {
    bareStartTag(w,tagName,v);
    for( Map.Entry e : (Set<Map.Entry>)v.entrySet() ) {
      bareStartTag(w,entryTag,null);
      Object key = e.getKey();
      if(key!=null) {
        w.startElement(keyTag,key);
        w.childAsXsiType(key,fieldName,keyBeanInfo, false);
        w.endElement();
      }
      Object value = e.getValue();
      if(value!=null) {
        w.startElement(valueTag,value);
        w.childAsXsiType(value,fieldName,valueBeanInfo, false);
        w.endElement();
      }
      w.endElement();
    }
    w.endElement();
  } else
  if(nillable) {
    w.startElement(tagName,null);
    w.writeXsiNilTrue();
    w.endElement();
  }
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

public final void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException {
  ListT list = acc.get(o);
  if(list!=null) {
    if(wrapperTagName!=null) {
      w.startElement(wrapperTagName,null);
      w.endNamespaceDecls(list);
      w.endAttributes();
    }
    serializeListBody(o,w,list);
    if(wrapperTagName!=null)
      w.endElement();
  } else {
    // list is null
    if(isWrapperNillable) {
      w.startElement(wrapperTagName,null);
      w.writeXsiNilTrue();
      w.endElement();
    } // otherwise don't print the wrapper tag name
  }
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

@Override
  public void writeLeafElement(XMLSerializer w, Name tagName, BeanT o, String fieldName) throws SAXException, AccessorException, IOException, XMLStreamException {
    w.startElement(tagName,null);
    declareNamespace(o,w);
    w.endNamespaceDecls(null);
    w.endAttributes();
    xducer.writeText(w,acc.get(o),fieldName);
    w.endElement();
  }
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

public void leafElement( Name tagName, String data, String fieldName ) throws SAXException, IOException, XMLStreamException {
  if(seenRoot) {
    textHasAlreadyPrinted = false;
    nse = nse.push();
    out.beginStartTag(tagName);
    out.endStartTag();
    if(data != null)
      try {
          out.text(data,false);
      } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(Messages.ILLEGAL_CONTENT.format(fieldName, e.getMessage()));
      }
    out.endTag(tagName);
    nse = nse.pop();
  } else {
    // root element has additional processing like xsi:schemaLocation,
    // so we need to go the slow way
    startElement(tagName,null);
    endNamespaceDecls(null);
    endAttributes();
      try {
        out.text(data, false);
      } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(Messages.ILLEGAL_CONTENT.format(fieldName, e.getMessage()));
      }
    endElement();
  }
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

@Override
public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException {
  boolean hasValue = xacc.hasValue(o);
  Object obj = null;
  try {
    obj = acc.getUnadapted(o);
  } catch (AccessorException ae) {
    ; // noop
  }
  Class valueType = acc.getValueType();
  // check for different type than expected. If found, add xsi:type declaration
  if (xsiTypeNeeded(o, w, obj, valueType)) {
    w.startElement(tagName, outerPeer);
    w.childAsXsiType(obj, fieldName, w.grammar.getBeanInfo(valueType), false);
    w.endElement();
  } else {  // current type is expected
    if (hasValue) {
      xacc.writeLeafElement(w, tagName, o, fieldName);
    } else if (nillable) {
      w.startElement(tagName, null);
      w.writeXsiNilTrue();
      w.endElement();
    }
  }
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

target.startElement(n.getNamespaceURI(),n.getLocalPart(),n.getPrefix(),null);
if(value==null) {
  target.writeXsiNilTrue();

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

@Override
public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException {
  ListT list = acc.get(o);
  if(list!=null) {
    if(xacc.useNamespace()) {
      w.startElement(tagName,null);
      xacc.declareNamespace(o,w);
      w.endNamespaceDecls(list);
      w.endAttributes();
      xacc.writeText(w,o,fieldName);
      w.endElement();
    } else {
      xacc.writeLeafElement(w, tagName, o, fieldName);
    }
  }
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

public void leafElement( Name tagName, Pcdata data, String fieldName ) throws SAXException, IOException, XMLStreamException {
  if(seenRoot) {
    textHasAlreadyPrinted = false;
    nse = nse.push();
    out.beginStartTag(tagName);
    out.endStartTag();
    if(data != null)
      out.text(data,false);
    out.endTag(tagName);
    nse = nse.pop();
  } else {
    // root element has additional processing like xsi:schemaLocation,
    // so we need to go the slow way
    startElement(tagName,null);
    endNamespaceDecls(null);
    endAttributes();
    out.text(data,false);
    endElement();
  }
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

try {
  prewrite(out, true, postInitAction);
  serializer.startElement(rootTagName,null);
  if(bi.jaxbType==Void.class || bi.jaxbType==void.class) {

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com