gpt4 book ai didi

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

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

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

XMLSerializer.addInscopeBinding介绍

[英]This method can be called after #startDocument is called but before the marshalling begins, to set the currently in-scope namespace bindings.

This method is useful to avoid redundant namespace declarations when the marshalling is producing a sub-document.
[中]可以在调用#startDocument之后但在编组开始之前调用此方法,以设置当前范围内的命名空间绑定。
当编组生成子文档时,此方法有助于避免冗余的命名空间声明。

代码示例

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

public void run() {
    Set<String> declaredPrefixes = new HashSet<String>();
    for( Node n=node; n!=null && n.getNodeType()==Node.ELEMENT_NODE; n=n.getParentNode() ) {
      NamedNodeMap atts = n.getAttributes();
      if(atts==null)      continue; // broken DOM. but be graceful.
      for( int i=0; i<atts.getLength(); i++ ) {
        Attr a = (Attr)atts.item(i);
        String nsUri = a.getNamespaceURI();
        if(nsUri==null || !nsUri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI))
          continue;   // not a namespace declaration
        String prefix = a.getLocalName();
        if(prefix==null)
          continue;   // broken DOM. skip to be safe
        if(prefix.equals("xmlns")) {
          prefix = "";
        }
        String value = a.getValue();
        if(value==null)
          continue;   // broken DOM. skip to be safe
        if(declaredPrefixes.add(prefix)) {
          serializer.addInscopeBinding(value,prefix);
        }
      }
    }
  }
}

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

public void run() {
    NamespaceContext ns = nsc;
    if(xsw!=null)   ns = xsw.getNamespaceContext();
    if(xew!=null)   ns = xew.getNamespaceContext();

    // StAX javadoc isn't very clear on the behavior,
    // so work defensively in anticipation of broken implementations.
    if(ns==null)
      return;

    // we can't enumerate all the in-scope namespace bindings in StAX,
    // so we only look for the known static namespace URIs.
    // this is less than ideal, but better than nothing.
    for( String nsUri : serializer.grammar.nameList.namespaceURIs ) {
      String p = ns.getPrefix(nsUri);
      if(p!=null)
        serializer.addInscopeBinding(nsUri,p);
    }
  }
}

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

private void prewrite(XmlOutput out, boolean fragment, Runnable postInitAction) throws IOException, SAXException, XMLStreamException {
  serializer.startDocument(out,fragment,getSchemaLocation(),getNoNSSchemaLocation());
  if(postInitAction!=null)    postInitAction.run();
  if(prefixMapper!=null) {
    // be defensive as we work with the user's code
    String[] decls = prefixMapper.getContextualNamespaceDecls();
    if(decls!=null) { // defensive check
      for( int i=0; i<decls.length; i+=2 ) {
        String prefix = decls[i];
        String nsUri = decls[i+1];
        if(nsUri!=null && prefix!=null) // defensive check
          serializer.addInscopeBinding(nsUri,prefix);
      }
    }
  }
  serializer.setPrefixMapper(prefixMapper);
}

代码示例来源:origin: org.glassfish.jaxb/jaxb-runtime

public void run() {
    Set<String> declaredPrefixes = new HashSet<String>();
    for( Node n=node; n!=null && n.getNodeType()==Node.ELEMENT_NODE; n=n.getParentNode() ) {
      NamedNodeMap atts = n.getAttributes();
      if(atts==null)      continue; // broken DOM. but be graceful.
      for( int i=0; i<atts.getLength(); i++ ) {
        Attr a = (Attr)atts.item(i);
        String nsUri = a.getNamespaceURI();
        if(nsUri==null || !nsUri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI))
          continue;   // not a namespace declaration
        String prefix = a.getLocalName();
        if(prefix==null)
          continue;   // broken DOM. skip to be safe
        if(prefix.equals("xmlns")) {
          prefix = "";
        }
        String value = a.getValue();
        if(value==null)
          continue;   // broken DOM. skip to be safe
        if(declaredPrefixes.add(prefix)) {
          serializer.addInscopeBinding(value,prefix);
        }
      }
    }
  }
}

代码示例来源:origin: org.glassfish.jaxb/jaxb-runtime

public void run() {
    NamespaceContext ns = nsc;
    if(xsw!=null)   ns = xsw.getNamespaceContext();
    if(xew!=null)   ns = xew.getNamespaceContext();

    // StAX javadoc isn't very clear on the behavior,
    // so work defensively in anticipation of broken implementations.
    if(ns==null)
      return;

    // we can't enumerate all the in-scope namespace bindings in StAX,
    // so we only look for the known static namespace URIs.
    // this is less than ideal, but better than nothing.
    for( String nsUri : serializer.grammar.nameList.namespaceURIs ) {
      String p = ns.getPrefix(nsUri);
      if(p!=null)
        serializer.addInscopeBinding(nsUri,p);
    }
  }
}

代码示例来源:origin: org.glassfish.jaxb/jaxb-runtime

private void prewrite(XmlOutput out, boolean fragment, Runnable postInitAction) throws IOException, SAXException, XMLStreamException {
  serializer.startDocument(out,fragment,getSchemaLocation(),getNoNSSchemaLocation());
  if(postInitAction!=null)    postInitAction.run();
  if(prefixMapper!=null) {
    // be defensive as we work with the user's code
    String[] decls = prefixMapper.getContextualNamespaceDecls();
    if(decls!=null) { // defensive check
      for( int i=0; i<decls.length; i+=2 ) {
        String prefix = decls[i];
        String nsUri = decls[i+1];
        if(nsUri!=null && prefix!=null) // defensive check
          serializer.addInscopeBinding(nsUri,prefix);
      }
    }
  }
  serializer.setPrefixMapper(prefixMapper);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.jaxb-impl

public void run() {
    Set<String> declaredPrefixes = new HashSet<String>();
    for( Node n=node; n!=null && n.getNodeType()==Node.ELEMENT_NODE; n=n.getParentNode() ) {
      NamedNodeMap atts = n.getAttributes();
      if(atts==null)      continue; // broken DOM. but be graceful.
      for( int i=0; i<atts.getLength(); i++ ) {
        Attr a = (Attr)atts.item(i);
        String nsUri = a.getNamespaceURI();
        if(nsUri==null || !nsUri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI))
          continue;   // not a namespace declaration
        String prefix = a.getLocalName();
        if(prefix==null)
          continue;   // broken DOM. skip to be safe
        if(prefix.equals("xmlns")) {
          prefix = "";
        }
        String value = a.getValue();
        if(value==null)
          continue;   // broken DOM. skip to be safe
        if(declaredPrefixes.add(prefix)) {
          serializer.addInscopeBinding(value,prefix);
        }
      }
    }
  }
}

代码示例来源:origin: apache/servicemix-bundles

public void run() {
    Set<String> declaredPrefixes = new HashSet<String>();
    for( Node n=node; n!=null && n.getNodeType()==Node.ELEMENT_NODE; n=n.getParentNode() ) {
      NamedNodeMap atts = n.getAttributes();
      if(atts==null)      continue; // broken DOM. but be graceful.
      for( int i=0; i<atts.getLength(); i++ ) {
        Attr a = (Attr)atts.item(i);
        String nsUri = a.getNamespaceURI();
        if(nsUri==null || !nsUri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI))
          continue;   // not a namespace declaration
        String prefix = a.getLocalName();
        if(prefix==null)
          continue;   // broken DOM. skip to be safe
        if(prefix.equals("xmlns")) {
          prefix = "";
        }
        String value = a.getValue();
        if(value==null)
          continue;   // broken DOM. skip to be safe
        if(declaredPrefixes.add(prefix)) {
          serializer.addInscopeBinding(value,prefix);
        }
      }
    }
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.jaxb-impl

public void run() {
    NamespaceContext ns = nsc;
    if(xsw!=null)   ns = xsw.getNamespaceContext();
    if(xew!=null)   ns = xew.getNamespaceContext();

    // StAX javadoc isn't very clear on the behavior,
    // so work defensively in anticipation of broken implementations.
    if(ns==null)
      return;

    // we can't enumerate all the in-scope namespace bindings in StAX,
    // so we only look for the known static namespace URIs.
    // this is less than ideal, but better than nothing.
    for( String nsUri : serializer.grammar.nameList.namespaceURIs ) {
      String p = ns.getPrefix(nsUri);
      if(p!=null)
        serializer.addInscopeBinding(nsUri,p);
    }
  }
}

代码示例来源:origin: apache/servicemix-bundles

public void run() {
    NamespaceContext ns = nsc;
    if(xsw!=null)   ns = xsw.getNamespaceContext();
    if(xew!=null)   ns = xew.getNamespaceContext();

    // StAX javadoc isn't very clear on the behavior,
    // so work defensively in anticipation of broken implementations.
    if(ns==null)
      return;

    // we can't enumerate all the in-scope namespace bindings in StAX,
    // so we only look for the known static namespace URIs.
    // this is less than ideal, but better than nothing.
    for( String nsUri : serializer.grammar.nameList.namespaceURIs ) {
      String p = ns.getPrefix(nsUri);
      if(p!=null)
        serializer.addInscopeBinding(nsUri,p);
    }
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.jaxb-impl

private void prewrite(XmlOutput out, boolean fragment, Runnable postInitAction) throws IOException, SAXException, XMLStreamException {
  serializer.startDocument(out,fragment,getSchemaLocation(),getNoNSSchemaLocation());
  if(postInitAction!=null)    postInitAction.run();
  if(prefixMapper!=null) {
    // be defensive as we work with the user's code
    String[] decls = prefixMapper.getContextualNamespaceDecls();
    if(decls!=null) { // defensive check
      for( int i=0; i<decls.length; i+=2 ) {
        String prefix = decls[i];
        String nsUri = decls[i+1];
        if(nsUri!=null && prefix!=null) // defensive check
          serializer.addInscopeBinding(nsUri,prefix);
      }
    }
  }
  serializer.setPrefixMapper(prefixMapper);
}

代码示例来源:origin: apache/servicemix-bundles

private void prewrite(XmlOutput out, boolean fragment, Runnable postInitAction) throws IOException, SAXException, XMLStreamException {
  serializer.startDocument(out,fragment,getSchemaLocation(),getNoNSSchemaLocation());
  if(postInitAction!=null)    postInitAction.run();
  if(prefixMapper!=null) {
    // be defensive as we work with the user's code
    String[] decls = prefixMapper.getContextualNamespaceDecls();
    if(decls!=null) { // defensive check
      for( int i=0; i<decls.length; i+=2 ) {
        String prefix = decls[i];
        String nsUri = decls[i+1];
        if(nsUri!=null && prefix!=null) // defensive check
          serializer.addInscopeBinding(nsUri,prefix);
      }
    }
  }
  serializer.setPrefixMapper(prefixMapper);
}

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