- All Superinterfaces:
- Node
- See Also:
- Top Examples, Source Code
String getName()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
Element getOwnerElement()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[38]_
By Ross Boss on 2002/09/09 18:00:26 Rate
Element atr = ( ( Attr ) node ) .getOwnerElement ( ) ;
TypeInfo getSchemaTypeInfo()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
boolean getSpecified()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
String getValue()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[1592]Get DOM node attributes
By Anonymous on 2005/11/04 20:23:08 Rate
//Traverse a DOM document using Apache xerces DocumentTraversal API
public static void usingTraversal ( Document doc ) {
if ( ! ( doc instanceof DocumentTraversal ) ) {
System.out.println ( "Not DocumentTraversal" ) ;
}
DocumentTraversal traversal = ( DocumentTraversal ) doc;
NodeIterator each = traversal.createNodeIterator ( doc,NodeFilter.SHOW_ELEMENT| NodeFilter.SHOW_PROCESSING_INSTRUCTION, null, false ) ;
Node walker=null;
while ( ( walker = each.nextNode ( ) ) != null ) {
if ( walker.getNodeType ( ) == Node.PROCESSING_INSTRUCTION_NODE ) {
ProcessingInstruction pi = ( ProcessingInstruction ) walker;
if ( "aTarget".equalsIgnoreCase ( pi.getTarget ( ) ) ) {
//When we find a certain ProcessingInstruction node
//replace it with a new ProcessingInstruction node with a different target
//do something with the data
System.out.println ( pi.getData ( ) ) ;
ProcessingInstruction newPI = doc.createProcessingInstruction ( "newTarget", pi.getData ( ) ) ;
pi.getParentNode ( ) .replaceChild ( pi, newPI ) ;
}
}
if ( walker.getNodeType ( ) == Node.ELEMENT_NODE ) {
NamedNodeMap attributes = walker.getAttributes ( ) ;
Attr attr = null;
for ( int i = 0; i < attributes.getLength ( ) ; i++ ) {
attr = ( Attr ) attributes.item ( i ) ;
//do something with the data
System.out.println ( attr.getValue ( ) ) ;
}
if ( walker.getChildNodes ( ) .getLength ( ) == 1 ) {
Node aNode = walker.getFirstChild ( ) ;
if ( aNode.getNodeType ( ) == Node.TEXT_NODE ) {
//do something with the data
System.out.println ( pi.getData ( ) ) ;
}
}
}
}
}
boolean isId()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
void setValue(String value)
throws DOMException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples