You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Doppeldiplomand <do...@gmx.de> on 2001/02/01 11:01:22 UTC

Extracting attribute-values from nodes

Hi,

how can I extract the attribute-value from attributes in nodes?
I know about the getAttribute()-method on elements, but is there a similar
method which works on nodes?
Or do I have to use a different way?
Christian


Make editings conform to XML Schema

Posted by ibrahim <ib...@natlab.research.philips.com>.
...sorry, i send this again. Looks like the previous one was not sent...

Hi,

I need to make sure any editings to XML document conform to its corresponding
XML Schema, so that any attempt of editing that doesn't conform the schema will
be rejected right away (not accepted first and checked later on)

I read in the archives that Xerces can tell a lot about schema by using
GrammarResolver. Jeff Lansing even kindly provides a code for it. But I'm new to
Java and I can't see how I can use it. I can't even understand what
GrammarResolver is doing.. does (GrammarResolver instance).getGrammar gives a
DOM tree of schema.. ? (tried to read the API but I find it not very
describing.. )

I use Xerces-J 1.2.3, with DOMParser to parse the document.

Can anyone plzzzzz help me ? Or if you have any suggestion of other means to do
this ? Would appreciate examples a lot..

thx,
cath



Re: Extracting attribute-values from nodes

Posted by Andy Clark <an...@apache.org>.
Doppeldiplomand wrote:
> how can I extract the attribute-value from attributes in nodes?
> I know about the getAttribute()-method on elements, but is there a similar
> method which works on nodes?
> Or do I have to use a different way?

  Node node = ...;
  String value = ((Element)node).getAttribute("attribute");

Elements are the only type of node that can have attributes.

-- 
Andy Clark * IBM, TRL - Japan * andyc@apache.org

RE: Extracting attribute-values from nodes

Posted by Jay Cain <ja...@cett.msstate.edu>.
Christian,

> how can I extract the attribute-value from attributes in nodes?
> I know about the getAttribute()-method on elements, but is there a similar
> method which works on nodes?

Try the getAttributes() method of the Node interface. It returns a
NamedNodeMap, so you can get the associated attributes from that.

- - - - -
Jay Cain
Center for Educational and Training Technology
Mississippi State University