Parsing Xml: Attributes.getvalue() Returns Null?
Solution 1:
Since one of the tags is "saxparser", I'm assuming that's what you're using. In that case, the method calls seem correct, leaving the problem to be that attributes
isn't correctly initialized with the values that your XML contains. Please add code to show how you generate attributes
.
EDIT: The problem is probably that
attributes.getValue("rows")
returns null since you aren't using qualified names in your XML; see the documentation on the SAX library, specifically the documentation of Attributes.getValue(String). If you use Attributes.getValue(String)
and qualified names aren't available, it will return null
.
A useful, but brief explanation of qualified names on SO can be found here.
EDIT2: I don't know how to properly adjust the XML (never used XML myself), but you don't have to use namespaces, you might be able to do what you want by using Attributes.getValue(int)
since that doesn't work on the names of the attributes but on the list of attributes it holds. You probably need to figure out the order of the attributes though; you could figure that out this way:
for(int i = 0; i < attributes.getLength(); i++) {
System.out.println(attributes.getValue(i));
}
Hope that helps; maybe you can find something helpful on namespaces in XML on SO; otherwise if your program requires the use of addressing attributes by their name, you probably will have to learn about XML namespaces.
Post a Comment for "Parsing Xml: Attributes.getvalue() Returns Null?"