سؤال

I have an XML message I am attempting to parse using GXT and AutoBeans. The root node of my XML has a namespace declaration and it appears that the AutoBean parser cannot read the XML.

I set up the root of the AutoBean object graph with a PropertyName specification:

@PropertyName("record")
RecordObject getRecord();

But when my XML looks like this:

<record xmlnms:ab="http://anynamespace.com">
<ab:name>SampleName</ab:name>
<ab:email>sample@email.com</ab:email>
</record>

The AutoBean can't seem to decode the XML. If the namespace declaration is not present, the AutoBean can find the root record object. Is there some other argument or something I can specify to tell the AutoBean to only look at the element name?

What I have tried

I tried to parse with the namespace stripped out and it works but in my real use case I am not able to remove the namespace declaration. I have also tried to specify the namespace in the @PropertyName attribute - @PropertyName("record xmlnms:ab=\"http://anynamespace.com\"") - but that does not work (nor did I expect it to).

EDIT

I am using GXT's XmlReader to try and parse the XML.

هل كانت مفيدة؟

المحلول

GXT's XmlReader sits on top of the build in XML parser that exists in the browser itself. It uses the com.google.gwt.xml.XML module in GWT to gain relatively consistent access to the XML nodes across all browsers, rather than building its own XML parser. By using the built-in implementation in the browser, GXT gets access to the native parser - and it turns out browsers are very good at parsing XML, since that's what they do all day, loading webpages.

Then, GXT has its own query engine to find nodes, in a query language that uses a combination of XPath and CSS3. This mix is to allow it to work well for looking for nodes in the html itself, as well as looking for nodes in xml documents. This is designed to be consisten

However, browsers have inconsistent support (I'm looking at you, IE) for namespaces, and so the XML module in GWT doesn't know how to talk about namespaces, and the DomQuery engine doesnt really either. Additionally, the : operator, which in XML means 'namespace', is used to mean 'psuedo-selector' in CSS, so the query language would be a little vague if it supported this directly: The string foo:bar could either mean "All elements with name foo that match psuedo-selector bar", or "All elements with name bar in the namespace foo".

So enough with the problem: whats the solution? At present, there isn't a good one for namespaced elements in IE6/IE7/IE8 - one part inconsistencies in the browsers and one part lack of ugly workaround in GXT means that you can't read out the elements directly. For all other browsers, to select elements like namespace:eltname, just use @PropertyName("eltname").

One other note: Due to the fact that attributes don't have psuedo-selectors, you can select them - @PropertyName("namespace:attrname") will correctly read out values in the attribute in <element namespace:attrname="value">.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top