tags:

views:

90

answers:

2

When I am parsing an xml string as below I get strange attributes like "autowire" with value "default". Is there anyway I can get only the attributes that are explicitly defined?

<bean id="aaaa" class="com.test.Service">
     <property name="cccc" ref="cccc"/>
</bean>

I am doing simple parsing turning it into a Document and then iterating over the Nodes.

Document document = docBuilder.parse(input);
NodeList nodeList = document.getChildNodes(); 
etc.
+2  A: 

It depends what you are using to parse. I'm guessing this is a Spring bean configuration file. Usually there's a XML Schema associated with it and that will dictate all default values for attributes.

So when the actual XML parser walks through the document, it will build some kind of representation (DOM parsers will obviously build a tree, SAX parsers will fire off events, etc) of the XML and insert those default values.

ilikeorangutans
+3  A: 

You can use following APIs to find whether an attribute is explicitly specified or not:

if you are using DOM: Attr.getSpecified()

if you are using SAX: Attributes2.isSpecified(qname)

Santhosh Kumar T