当前位置: 首页>>代码示例>>Java>>正文


Java SerializationHandler.addAttribute方法代码示例

本文整理汇总了Java中org.apache.xml.serializer.SerializationHandler.addAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java SerializationHandler.addAttribute方法的具体用法?Java SerializationHandler.addAttribute怎么用?Java SerializationHandler.addAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.xml.serializer.SerializationHandler的用法示例。


在下文中一共展示了SerializationHandler.addAttribute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addAttribute

import org.apache.xml.serializer.SerializationHandler; //导入方法依赖的package包/类
/**
 * Copy an DOM attribute to the created output element, executing
 * attribute templates as need be, and processing the xsl:use
 * attribute.
 *
 * @param handler SerializationHandler to which the attributes are added.
 * @param attr Attribute node to add to SerializationHandler.
 *
 * @throws TransformerException
 */
public static void addAttribute(SerializationHandler handler, int attr)
    throws TransformerException
{

    TransformerImpl transformer =
        (TransformerImpl) handler.getTransformer();
    DTM dtm = transformer.getXPathContext().getDTM(attr);

    if (SerializerUtils.isDefinedNSDecl(handler, attr, dtm))
        return;

    String ns = dtm.getNamespaceURI(attr);

    if (ns == null)
        ns = "";

    // %OPT% ...can I just store the node handle?
    try
    {
        handler.addAttribute(
            ns,
            dtm.getLocalName(attr),
            dtm.getNodeName(attr),
            "CDATA",
            dtm.getNodeValue(attr), false);
    }
    catch (SAXException e)
    {
        // do something?
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:42,代码来源:SerializerUtils.java

示例2: constructNode

import org.apache.xml.serializer.SerializationHandler; //导入方法依赖的package包/类
/**
 * Construct a node in the result tree.  This method is overloaded by 
 * xsl:attribute. At this class level, this method creates an element.
 *
 * @param nodeName The name of the node, which may be null.
 * @param prefix The prefix for the namespace, which may be null.
 * @param nodeNamespace The namespace of the node, which may be null.
 * @param transformer non-null reference to the the current transform-time state.
 * @param sourceNode non-null reference to the <a href="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
 * @param mode reference, which may be null, to the <a href="http://www.w3.org/TR/xslt#modes">current mode</a>.
 *
 * @throws TransformerException
 */
void constructNode(
        String nodeName, String prefix, String nodeNamespace, TransformerImpl transformer)
          throws TransformerException
{

  if(null != nodeName && nodeName.length() > 0)
  {
    SerializationHandler rhandler = transformer.getSerializationHandler();

    // Evaluate the value of this attribute
    String val = transformer.transformToString(this);
    try 
    {
      // Let the result tree handler add the attribute and its String value.
      String localName = QName.getLocalPart(nodeName);
      if(prefix != null && prefix.length() > 0){
          rhandler.addAttribute(nodeNamespace, localName, nodeName, "CDATA", val, true);
      }else{
          rhandler.addAttribute("", localName, nodeName, "CDATA", val, true);
      }
    }
    catch (SAXException e)
    {
    }
  }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:40,代码来源:ElemAttribute.java

示例3: copyAttribute

import org.apache.xml.serializer.SerializationHandler; //导入方法依赖的package包/类
/**
 * Copy an Attribute node to a SerializationHandler
 *
 * @param nodeID The node identity
 * @param exptype The expanded type of the Element node
 * @param handler The SerializationHandler
 */
protected final void copyAttribute(int nodeID, int exptype,
    SerializationHandler handler)
    throws SAXException
{
    /*
        final String uri = getNamespaceName(node);
        if (uri.length() != 0) {
            final String prefix = getPrefix(node);
            handler.namespaceAfterStartElement(prefix, uri);
        }
        handler.addAttribute(getNodeName(node), getNodeValue(node));
    */
    final ExtendedType extType = m_extendedTypes[exptype];
    final String uri = extType.getNamespace();
    final String localName = extType.getLocalName();

    String prefix = null;
    String qname = null;
    int dataIndex = _dataOrQName(nodeID);
    int valueIndex = dataIndex;
        if (dataIndex <= 0) {
            int prefixIndex = m_data.elementAt(-dataIndex);
            valueIndex = m_data.elementAt(-dataIndex+1);
            qname = m_valuesOrPrefixes.indexToString(prefixIndex);
            int colonIndex = qname.indexOf(':');
            if (colonIndex > 0) {
                prefix = qname.substring(0, colonIndex);
            }
        }
        if (uri.length() != 0) {
            handler.namespaceAfterStartElement(prefix, uri);
        }

    String nodeName = (prefix != null) ? qname : localName;
    String nodeValue = (String)m_values.elementAt(valueIndex);

    handler.addAttribute(nodeName, nodeValue);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:46,代码来源:SAX2DTM2.java


注:本文中的org.apache.xml.serializer.SerializationHandler.addAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。