當前位置: 首頁>>代碼示例>>Java>>正文


Java XMLConstants.XMLNS_ATTRIBUTE屬性代碼示例

本文整理匯總了Java中javax.xml.XMLConstants.XMLNS_ATTRIBUTE屬性的典型用法代碼示例。如果您正苦於以下問題:Java XMLConstants.XMLNS_ATTRIBUTE屬性的具體用法?Java XMLConstants.XMLNS_ATTRIBUTE怎麽用?Java XMLConstants.XMLNS_ATTRIBUTE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在javax.xml.XMLConstants的用法示例。


在下文中一共展示了XMLConstants.XMLNS_ATTRIBUTE屬性的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getPrefixes

/**
   * @return mapping from prefix to namespace.
   */
  public Map<String, String> getPrefixes() {
      Map<String,String> prefixes = new HashMap<String,String>();
      NamedNodeMap nodes = getPeer().getAttributes();
      for (int i = 0; i < nodes.getLength(); i++) {
          Node n = nodes.item(i);
          String name = n.getLocalName();
   String prefix = n.getPrefix();
   final String xmlns = XMLConstants.XMLNS_ATTRIBUTE; //NOI18N
   if (xmlns.equals(name) || // default namespace
xmlns.equals(prefix)) { // namespace prefix
String ns = n.getNodeValue();
prefixes.put(name, ns);
   }
      }
      String defaultNamespace = prefixes.remove(XMLConstants.XMLNS_ATTRIBUTE);
      if (defaultNamespace != null) {
          prefixes.put(XMLConstants.DEFAULT_NS_PREFIX, defaultNamespace);
      }
      return prefixes;
  }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:AbstractDocumentComponent.java

示例2: cloneNode

public Element cloneNode(boolean deep, boolean cloneNamespacePrefix) {
     Document root = isInTree() ? (Document) getOwnerDocument() : null;
     Map<Integer,String> allNamespaces = null;
     if (root != null && cloneNamespacePrefix) {
         allNamespaces = root.getNamespaceMap();
     }
     Map<String,String> clonePrefixes = new HashMap<String,String>();
     Element clone = (Element) super.cloneNode(deep, allNamespaces, clonePrefixes);
     for (Map.Entry e : clonePrefixes.entrySet()) {
String prefix = (String) e.getKey();
         String attr = prefix.length() > 0 ? 
             XMLConstants.XMLNS_ATTRIBUTE+":"+prefix : 
             XMLConstants.XMLNS_ATTRIBUTE;
         Attribute attrNode = new Attribute(attr, (String) e.getValue());
         clone.setAttributeNode(attrNode);
     }
     return clone;
 }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:Element.java

示例3: getPrefix

@Override
public String getPrefix(String uri) {
    if( uri==null )
        throw new IllegalArgumentException();
    if( uri.equals(XMLConstants.XML_NS_URI) )
        return XMLConstants.XML_NS_PREFIX;
    if( uri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI) )
        return XMLConstants.XMLNS_ATTRIBUTE;

    for( int i=nsLen-2; i>=0; i-=2 )
        if(uri.equals(nsBind[i+1]))
            if( getNamespaceURI(nsBind[i]).equals(nsBind[i+1]) )
                // make sure that this prefix is still effective.
                return nsBind[i];

    if(environmentNamespaceContext!=null)
        return environmentNamespaceContext.getPrefix(uri);

    return null;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:20,代碼來源:UnmarshallingContext.java

示例4: writeNamespace

/**
 * creates a namespace attribute and will associate it with the current element in
 * the DOM tree.
 * @param prefix {@inheritDoc}
 * @param namespaceURI {@inheritDoc}
 * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
 */
public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {

    if (prefix == null) {
        throw new XMLStreamException("prefix cannot be null");
    }

    if (namespaceURI == null) {
        throw new XMLStreamException("NamespaceURI cannot be null");
    }

    String qname = null;

    if (prefix.equals("")) {
        qname = XMLConstants.XMLNS_ATTRIBUTE;
    } else {
        qname = getQName(XMLConstants.XMLNS_ATTRIBUTE,prefix);
    }

    ((Element)currentNode).setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,qname, namespaceURI);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:27,代碼來源:XMLDOMWriterImpl.java

示例5: addNamespace

/**
 * Processes an attribute for namespace-related stuff. Detects and sets
 * {@link #schemaLocation}, {@link #noNamespaceSchemaLocation}, {@link #defaultNamespace} URIs.
 * Should be called for elements starting from root down to the context element for
 * proper overriding
 */
private void addNamespace(String attrName, String value, String nodePrefix) {
    String defNS = XMLConstants.XMLNS_ATTRIBUTE;

    if(CompletionUtil.getLocalNameFromTag(attrName).
            equals(XSI_SCHEMALOCATION)) {
        schemaLocation = value.trim();
        return;
    } 
    if(CompletionUtil.getLocalNameFromTag(attrName).
            equals(XSI_NONS_SCHEMALOCATION)) {
        noNamespaceSchemaLocation = value.trim();
        return;
    }  
    if (CompletionUtil.getLocalNameFromTag(attrName).
            equals(XSD_TARGET_NAMESPACE)) {
        targetNamespace = value.trim();
        return;
    }

    if(! attrName.startsWith(XMLConstants.XMLNS_ATTRIBUTE))
        return;            

    if(attrName.equals(defNS)) {
        this.defaultNamespace = value;
    }
    declaredNamespaces.put(attrName, value);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:33,代碼來源:CompletionContextImpl.java

示例6: getPrefix

@Override
public String getPrefix(String uri) {
	if (defaultNamespaceURI != null && defaultNamespaceURI.equals(uri)) {
		return XMLConstants.DEFAULT_NS_PREFIX;
	} else if (uri == null) {
		throw new IllegalArgumentException("Null not allowed as prefix");
	} else if (uri.equals(XMLConstants.XML_NS_URI)) {
		return XMLConstants.XML_NS_PREFIX;
	} else if (uri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
		return XMLConstants.XMLNS_ATTRIBUTE;
	} else {
		return namespaceIdsMap.get(uri);
	}
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:14,代碼來源:MapBasedNamespaceContext.java

示例7: main

public static void main (final String [] args)
{
  final File aSchFile = new File ("../../../schematron/EN16931-EDIFACT-validation.sch");
  final File aXsltFile = new File ("../../../stylesheet/EN16931-EDIFACT-validation-compiled.xsl");

  logger.info ("Reading Schematron");
  final SchematronResourceSCH aSch = SchematronResourceSCH.fromFile (aSchFile);
  final ISchematronXSLTBasedProvider aXsltProvider = aSch.getXSLTProvider ();

  // Write the resulting XSLT file to disk
  final MapBasedNamespaceContext aNSContext = new MapBasedNamespaceContext ().addMapping ("svrl",
                                                                                          CSVRL.SVRL_NAMESPACE_URI);
  // Add all namespaces from XSLT document root
  final String sNSPrefix = XMLConstants.XMLNS_ATTRIBUTE + ":";
  XMLHelper.getAllAttributesAsMap (aXsltProvider.getXSLTDocument ().getDocumentElement ())
           .forEach ( (sAttrName, sAttrValue) -> {
             if (sAttrName.startsWith (sNSPrefix))
               aNSContext.addMapping (sAttrName.substring (sNSPrefix.length ()), sAttrValue);
           });

  final XMLWriterSettings aXWS = new XMLWriterSettings ();
  aXWS.setNamespaceContext (aNSContext).setPutNamespaceContextPrefixesInRoot (true);

  logger.info ("Writing XSLT");
  final OutputStream aOS = FileHelper.getOutputStream (aXsltFile);
  XMLWriter.writeToStream (aXsltProvider.getXSLTDocument (), aOS, aXWS);

  logger.info ("Done");
}
 
開發者ID:CenPC434,項目名稱:java-tools,代碼行數:29,代碼來源:MainCreateXSLTFromSchematron.java

示例8: getPrefix

@Override
public String getPrefix(String namespaceUri) {
    if (null == namespaceUri) {
        throw new IllegalArgumentException("namespaceURI");
    } else if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceUri)) {
        return XMLConstants.XMLNS_ATTRIBUTE;
    } else if (XMLConstants.XML_NS_URI.equals(namespaceUri)) {
        return XMLConstants.XML_NS_PREFIX;
    } else if ("http://www.example.com/my".equals(namespaceUri)) {
        return "my";
    } else {
        return XMLConstants.DEFAULT_NS_PREFIX;
    }
}
 
開發者ID:SimY4,項目名稱:xpath-to-xml,代碼行數:14,代碼來源:SimpleNamespaceContext.java

示例9: writeDefaultNamespace

/**
 * Creates a DOM attribute and adds it to the current element in the DOM tree.
 * @param namespaceURI {@inheritDoc}
 * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
 */
public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException {
    if(currentNode.getNodeType() == Node.ELEMENT_NODE){
        String qname = XMLConstants.XMLNS_ATTRIBUTE;
        ((Element)currentNode).setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,qname, namespaceURI);
    }else{
        //Convert node type to String
        throw new IllegalStateException("Current DOM Node type  is "+ currentNode.getNodeType() +
                "and does not allow attributes to be set ");
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:15,代碼來源:XMLDOMWriterImpl.java

示例10: populateNamespaces

/**
 * Keeps all namespaces along with their prefixes in a HashMap.
 * This is obtained from the root element's attributes, with
 * the attribute value(namespace) as the key and name with prefix
 * as the value.
 * For example the hashmap may look like this
 *  KEY                                    VALUE
 *  http://www.camera.com                  xmlns:c
 *  http://www.nikon.com                   xmlns:n
 */
private void populateNamespaces() {
    if(docRoot == null)
        return;
    //Check if the tag has any prefix. If yes, the defaultNamespace
    //is the one with this prefix.
    String tagName = docRoot.getName();
    String defNS = XMLConstants.XMLNS_ATTRIBUTE;
    String temp = CompletionUtil.getPrefixFromTag(tagName);
    if(temp != null) defNS = defNS+":"+temp; //NOI18N
    List<DocRootAttribute> attributes = docRoot.getAttributes();
    
    String version = null;
    boolean xsltDeclared = false;
    
    for(int index=0; index<attributes.size(); index++) {
        DocRootAttribute attr = attributes.get(index);
        String attrName = attr.getName();
        String value = attr.getValue();
        addNamespace(attrName, value, temp);

        //resolve xsl stylesheets w/o the schema location specification.
        //In such case the root element only contains the xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"
        //along with the version attribute.
        //If such ns is declared and the version is 2.0 then use the 
        //http://www.w3.org/2007/schema-for-xslt20.xsd schema for the completion model
        
        if(attr.getValue().trim().equals("http://www.w3.org/1999/XSL/Transform")) { //NOI18N
            xsltDeclared = true;
        }
        if(CompletionUtil.getLocalNameFromTag(attrName).
                equals("version")) { //NOI18N
            version = attr.getValue().trim();
        }
    }
    
    if(schemaLocation == null && xsltDeclared && "2.0".equals(version)) {
        //only the second "token" from the schemaLocation is considered as the schema
        schemaLocation = "schema http://www.w3.org/2007/schema-for-xslt20.xsd"; //NOI18N
    }
    
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:51,代碼來源:CompletionContextImpl.java

示例11: NamespaceImpl

/** Creates a new instance of NamespaceImpl */
public NamespaceImpl(String namespaceURI) {
    super(XMLConstants.XMLNS_ATTRIBUTE,XMLConstants.XMLNS_ATTRIBUTE_NS_URI,XMLConstants.DEFAULT_NS_PREFIX,namespaceURI,null);
    init();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:5,代碼來源:NamespaceImpl.java


注:本文中的javax.xml.XMLConstants.XMLNS_ATTRIBUTE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。