本文整理汇总了Java中org.w3c.dom.Node类的典型用法代码示例。如果您正苦于以下问题:Java Node类的具体用法?Java Node怎么用?Java Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Node类属于org.w3c.dom包,在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFirstVisibleChildElement
import org.w3c.dom.Node; //导入依赖的package包/类
/** Finds and returns the first visible child element node. */
public static Element getFirstVisibleChildElement(Node parent, Hashtable hiddenNodes) {
// search for node
Node child = parent.getFirstChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE &&
!isHidden(child, hiddenNodes)) {
return (Element)child;
}
child = child.getNextSibling();
}
// not found
return null;
}
示例2: getNamespacePrefix
import org.w3c.dom.Node; //导入依赖的package包/类
public String getNamespacePrefix(String uri) {
NamespaceContextIterator eachNamespace = getNamespaceContextNodes();
while (eachNamespace.hasNext()) {
org.w3c.dom.Attr namespaceDecl = eachNamespace.nextNamespaceAttr();
if (namespaceDecl.getNodeValue().equals(uri)) {
String candidatePrefix = namespaceDecl.getLocalName();
if ("xmlns".equals(candidatePrefix))
return "";
else
return candidatePrefix;
}
}
// Find if any of the ancestors' name has this uri
org.w3c.dom.Node currentAncestor = this;
while (currentAncestor != null &&
!(currentAncestor instanceof Document)) {
if (uri.equals(currentAncestor.getNamespaceURI()))
return currentAncestor.getPrefix();
currentAncestor = currentAncestor.getParentNode();
}
return null;
}
示例3: displayMetadata
import org.w3c.dom.Node; //导入依赖的package包/类
static void displayMetadata(Node node, int level) {
for (int i = 0; i < level; i++) System.out.print(" ");
System.out.print("<" + node.getNodeName());
NamedNodeMap map = node.getAttributes();
if (map != null) { // print attribute values
int length = map.getLength();
for (int i = 0; i < length; i++) {
Node attr = map.item(i);
System.out.print(" " + attr.getNodeName() +
"=\"" + attr.getNodeValue() + "\"");
}
}
Node child = node.getFirstChild();
if (child != null) {
System.out.println(">"); // close current tag
while (child != null) { // emit child tags recursively
displayMetadata(child, level + 1);
child = child.getNextSibling();
}
for (int i = 0; i < level; i++) System.out.print(" ");
System.out.println("</" + node.getNodeName() + ">");
} else {
System.out.println("/>");
}
}
示例4: readBars
import org.w3c.dom.Node; //导入依赖的package包/类
public void readBars(){
if( this.xmlDocument != null ){
NodeList barNodes = getChildNodeList(this.xmlDocument.getFirstChild(), "Bars");
for( int i = 0 ; i < barNodes.getLength() ; i ++ ){
Node barNode = barNodes.item( i );
if( barNode.getNodeName().equals("Bar") ){
GPXBar bar = new GPXBar();
bar.setId(getAttributeIntegerValue(barNode, "id"));
bar.setVoiceIds( getChildNodeIntegerContentArray(barNode, "Voices"));
bar.setClef(getChildNodeContent(barNode, "Clef"));
bar.setSimileMark(getChildNodeContent(barNode,"SimileMark"));
this.gpxDocument.getBars().add( bar );
}
}
}
}
示例5: isLegalContainedNode
import org.w3c.dom.Node; //导入依赖的package包/类
/**
* Returns true IFF the given node can be contained by
* a range.
*/
private boolean isLegalContainedNode( Node node )
{
if ( node==null )
return false;
switch( node.getNodeType() )
{
case Node.DOCUMENT_NODE:
case Node.DOCUMENT_FRAGMENT_NODE:
case Node.ATTRIBUTE_NODE:
case Node.ENTITY_NODE:
case Node.NOTATION_NODE:
return false;
}
return true;
}
示例6: endNode
import org.w3c.dom.Node; //导入依赖的package包/类
/**
* End processing of given node
*
*
* @param node Node we just finished processing
*
* @throws org.xml.sax.SAXException
*/
protected void endNode(Node node) throws org.xml.sax.SAXException {
switch (node.getNodeType()) {
case Node.DOCUMENT_NODE :
break;
case Node.DOCUMENT_TYPE_NODE :
serializeDocType((DocumentType) node, false);
break;
case Node.ELEMENT_NODE :
serializeElement((Element) node, false);
break;
case Node.CDATA_SECTION_NODE :
break;
case Node.ENTITY_REFERENCE_NODE :
serializeEntityReference((EntityReference) node, false);
break;
default :
}
}
示例7: intersection
import org.w3c.dom.Node; //导入依赖的package包/类
/**
* The set:intersection function returns a node set comprising the nodes that are within
* both the node sets passed as arguments to it.
*
* @param nl1 NodeList for first node-set.
* @param nl2 NodeList for second node-set.
* @return a NodeList containing the nodes in nl1 that are also
* in nl2.
*
* @see <a href="http://www.exslt.org/">EXSLT</a>
*/
public static NodeList intersection(NodeList nl1, NodeList nl2)
{
NodeSet ns1 = new NodeSet(nl1);
NodeSet ns2 = new NodeSet(nl2);
NodeSet inter = new NodeSet();
inter.setShouldCacheNodes(true);
for (int i = 0; i < ns1.getLength(); i++)
{
Node n = ns1.elementAt(i);
if (ns2.contains(n))
inter.addElement(n);
}
return inter;
}
示例8: getPreviousLogicalSibling
import org.w3c.dom.Node; //导入依赖的package包/类
private Node getPreviousLogicalSibling(Node n) {
Node prev = n.getPreviousSibling();
// If "n" has no previous sibling and its parent is an entity reference node we
// need to continue the search through the previous siblings of the entity
// reference as these are logically siblings of the given node.
if (prev == null) {
Node parent = n.getParentNode();
while (parent != null && parent.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
prev = parent.getPreviousSibling();
if (prev != null) {
break;
}
parent = parent.getParentNode();
}
}
return prev;
}
示例9: replaceChild
import org.w3c.dom.Node; //导入依赖的package包/类
/**
* Make newChild occupy the location that oldChild used to
* have. Note that newChild will first be removed from its previous
* parent, if any. Equivalent to inserting newChild before oldChild,
* then removing oldChild.
*
* @return oldChild, in its new state (removed).
*
* @throws DOMException(HIERARCHY_REQUEST_ERR) if newChild is of a
* type that shouldn't be a child of this node, or if newChild is
* one of our ancestors.
*
* @throws DOMException(WRONG_DOCUMENT_ERR) if newChild has a
* different owner document than we do.
*
* @throws DOMException(NOT_FOUND_ERR) if oldChild is not a child of
* this node.
*
* @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if this node is
* read-only.
*/
public Node replaceChild(Node newChild, Node oldChild)
throws DOMException {
makeChildNode();
// If Mutation Events are being generated, this operation might
// throw aggregate events twice when modifying an Attr -- once
// on insertion and once on removal. DOM Level 2 does not specify
// this as either desirable or undesirable, but hints that
// aggregations should be issued only once per user request.
// notify document
CoreDocumentImpl ownerDocument = ownerDocument();
ownerDocument.replacingNode(this);
internalInsertBefore(newChild, oldChild, true);
if (newChild != oldChild) {
internalRemoveChild(oldChild, true);
}
// notify document
ownerDocument.replacedNode(this);
return oldChild;
}
示例10: encryptElement
import org.w3c.dom.Node; //导入依赖的package包/类
/**
* Encrypts an <code>Element</code> and replaces it with its encrypted
* counterpart in the context <code>Document</code>, that is, the
* <code>Document</code> specified when one calls
* {@link #getInstance(String) getInstance}.
*
* @param element the <code>Element</code> to encrypt.
* @return the context <code>Document</code> with the encrypted
* <code>Element</code> having replaced the source <code>Element</code>.
* @throws Exception
*/
private Document encryptElement(Element element) throws Exception{
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Encrypting element...");
}
if (null == element) {
log.log(java.util.logging.Level.SEVERE, "Element unexpectedly null...");
}
if (cipherMode != ENCRYPT_MODE && log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "XMLCipher unexpectedly not in ENCRYPT_MODE...");
}
if (algorithm == null) {
throw new XMLEncryptionException("XMLCipher instance without transformation specified");
}
encryptData(contextDocument, element, false);
Element encryptedElement = factory.toElement(ed);
Node sourceParent = element.getParentNode();
sourceParent.replaceChild(encryptedElement, element);
return contextDocument;
}
示例11: KalturaAssetDistributionPropertyCondition
import org.w3c.dom.Node; //导入依赖的package包/类
public KalturaAssetDistributionPropertyCondition(Element node) throws KalturaApiException {
super(node);
NodeList childNodes = node.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node aNode = childNodes.item(i);
String nodeName = aNode.getNodeName();
String txt = aNode.getTextContent();
if (nodeName.equals("propertyName")) {
this.propertyName = ParseUtils.parseString(txt);
continue;
} else if (nodeName.equals("propertyValue")) {
this.propertyValue = ParseUtils.parseString(txt);
continue;
}
}
}
开发者ID:ITYug,项目名称:kaltura-ce-sakai-extension,代码行数:17,代码来源:KalturaAssetDistributionPropertyCondition.java
示例12: visit
import org.w3c.dom.Node; //导入依赖的package包/类
private void visit( Node n ) throws SAXException {
setCurrentLocation( n );
// if a case statement gets too big, it should be made into a separate method.
switch(n.getNodeType()) {
case Node.CDATA_SECTION_NODE:
case Node.TEXT_NODE:
String value = n.getNodeValue();
receiver.characters( value.toCharArray(), 0, value.length() );
break;
case Node.ELEMENT_NODE:
visit( (Element)n );
break;
case Node.ENTITY_REFERENCE_NODE:
receiver.skippedEntity(n.getNodeName());
break;
case Node.PROCESSING_INSTRUCTION_NODE:
ProcessingInstruction pi = (ProcessingInstruction)n;
receiver.processingInstruction(pi.getTarget(),pi.getData());
break;
}
}
示例13: removeManifestVersions
import org.w3c.dom.Node; //导入依赖的package包/类
/**
* Removes attributes like "versionCode" and "versionName" from file.
*
* @param file File representing AndroidManifest.xml
* @throws AndrolibException
*/
public static void removeManifestVersions(File file) throws AndrolibException {
if (file.exists()) {
try {
Document doc = loadDocument(file);
Node manifest = doc.getFirstChild();
NamedNodeMap attr = manifest.getAttributes();
Node vCode = attr.getNamedItem("android:versionCode");
Node vName = attr.getNamedItem("android:versionName");
if (vCode != null) {
attr.removeNamedItem("android:versionCode");
}
if (vName != null) {
attr.removeNamedItem("android:versionName");
}
saveDocument(file, doc);
} catch (SAXException | ParserConfigurationException | IOException | TransformerException ignored) {
}
}
}
示例14: removeUserDefinedNodes
import org.w3c.dom.Node; //导入依赖的package包/类
private void removeUserDefinedNodes(Element parent) {
HashSet<Node> toRemove = new HashSet<Node>();
NodeList list = parent.getChildNodes();
for (int i=0; i<list.getLength(); i++) {
Node node = list.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
((Element)node).removeAttribute("done");
((Element)node).removeAttribute("hashcode");
if (node.getNodeName().equals("schema-type")) {
toRemove.add(node);
}
else {
removeUserDefinedNodes((Element)node);
}
}
}
Iterator<Node> it = toRemove.iterator();
while (it.hasNext()) {
parent.removeChild(it.next());
}
toRemove.clear();
}
示例15: assertRevenueShareDetails_BrokerService
import org.w3c.dom.Node; //导入依赖的package包/类
public void assertRevenueShareDetails_BrokerService(String marketplaceId,
VOService service, String expectedServiceRevenue,
String expectedMarketplacePercentage,
String expectedMarketplaceRevenue,
String expectedOperatorPercentage, String expectedOperatorRevenue,
String expectedBrokerPercentage, String expectedBrokerRevenue,
String expectedSupplierAmount) throws Exception {
Node revenueShareDetails = assertRevenueShareDetails(marketplaceId,
service, expectedServiceRevenue, expectedMarketplacePercentage,
expectedMarketplaceRevenue, expectedOperatorPercentage,
expectedOperatorRevenue, expectedSupplierAmount);
assertAttribute(
revenueShareDetails,
BillingShareResultXmlTags.ATTRIBUTE_NAME_BROKER_REVENUE_SHARE_PERCENTAGE,
expectedBrokerPercentage);
assertAttribute(revenueShareDetails,
BillingShareResultXmlTags.ATTRIBUTE_NAME_BROKER_REVENUE,
expectedBrokerRevenue);
}