XML parser converts nodeNames to lowercase

9 views
Skip to first unread message

nuno

unread,
May 29, 2008, 3:12:36 PM5/29/08
to Google Web Toolkit
Is this the way it should work or is it some problem?

If other people think it should work like this I will get a simple
code example of the prob.

GWT1.5 RC1

Thanks for the help,

Nuno

Peter Blazejewicz

unread,
May 29, 2008, 5:18:39 PM5/29/08
to Google Web Toolkit
hi Nuno,

from what I know in javascript/DOM nodeName always (is supposed)
returns UPPERCASE names (that was something that got me few errors
when I started native javascript renently),
see quirksmode page:
http://www.quirksmode.org/dom/w3c_core.html#nodeinformation
if I understand corectly GWT Node (from xml module) is just wrapper
for DOM node and it should return UPPERCASE as well,
is that you are bothered about?

regards,
Peter

nuno

unread,
May 31, 2008, 7:25:08 AM5/31/08
to Google Web Toolkit
Hi Peter,

Thanks for your reply but I was referring to an XML being returned as
response to a formPanel. (I know my first post was totally unclear,
sorry)

Starting again:

I have a LAMP server and I am using a FormPanel to send information
for the server and process an XML response. I now found that my
problems are bigger than just the uppercase issue.
I now think that IE and FF are playing games with me.

The GWT code:
package com.mycompany.project.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.FormHandler;
import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.FormSubmitCompleteEvent;
import com.google.gwt.user.client.ui.FormSubmitEvent;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Hidden;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.xml.client.Document;
import com.google.gwt.xml.client.Element;
import com.google.gwt.xml.client.NodeList;
import com.google.gwt.xml.client.XMLParser;

import java.util.HashMap;

/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class TestFormPanel implements EntryPoint {
private FormPanel formPanel = new FormPanel();
private RootPanel rootPanel = RootPanel.get();
private VerticalPanel vPanel = new VerticalPanel();
private HorizontalPanel h1Panel = new HorizontalPanel();

public void onModuleLoad() {
formPanel.setAction("testFormPanel.php");
formPanel.setMethod(FormPanel.METHOD_POST);
formPanel.setEncoding(FormPanel.ENCODING_URLENCODED);

h1Panel.add( new Hidden("source","1"));
h1Panel.add( new Hidden("source_URI","herehere"));
h1Panel.add( new Hidden("username","myusername"));
h1Panel.add( new Hidden("session_hash","ejdjieewiu32eru"));

Button formButton = new Button("Press here", new ClickListener() {
public void onClick(Widget sender) {
formPanel.submit();
}
});

h1Panel.add(formButton);
formPanel.add(h1Panel);
vPanel.add(formPanel);
formPanel.addFormHandler(new FormHandler() {
public void onSubmit(FormSubmitEvent event) {
// Does Nothing
}

public void onSubmitComplete(FormSubmitCompleteEvent event) {
Label outputLabel = new Label(event.getResults());
vPanel.add(outputLabel);
HTMLPanel outputLabel1 = new HTMLPanel("Plain script result:
<br><br>" + event.getResults() + "<br><br>");
vPanel.add(outputLabel1);
Window.alert("Press to continue");
HashMap<String, String> parsedResponse = new HashMap<String,
String>();
parsedResponse = parseResponse(event.getResults());
HTMLPanel outputLabel2 = new HTMLPanel("Parsed Results:
<br><br>" + parsedResponse.toString());
vPanel.add(outputLabel2);

}


});

rootPanel.add(vPanel);
}

public HashMap<String, String> parseResponse(String responseXML) {
HTMLPanel htmlPanel = new HTMLPanel("Inside parsing function:
<br>" + responseXML + "<br><br>");
vPanel.add(htmlPanel);
Document response = XMLParser.parse(responseXML);
Element begagaElement = response.getDocumentElement();
XMLParser.removeWhitespace(begagaElement);

// ERROR XML file Section
Element ErrorsElement = (Element)
begagaElement.getElementsByTagName("errors").item(0);
Integer numErrors = new
Integer(ErrorsElement.getAttribute("num_errors"));
Element resultsElement = (Element)
begagaElement.getElementsByTagName("results").item(0);
Integer numResults = new
Integer(resultsElement.getAttribute("num_results"));

HashMap<String, String> parsedResponse = new HashMap<String,
String>();
parsedResponse.put(new String("numErrors"),
numErrors.toString());

NodeList errors = ErrorsElement.getElementsByTagName("error");
for (int i = 0; i < numErrors; i++){
Element errorElement = (Element) errors.item(i);
Integer errorNumber = i + 1;
parsedResponse.put("Error-" + errorNumber.toString() + "-Text",
errorElement.getElementsByTagName("text").item(0).getFirstChild().getNodeValue());
parsedResponse.put("Error-" + errorNumber.toString() + "-Code",
errorElement.getElementsByTagName("code").item(0).getFirstChild().getNodeValue());
}

// Results XML file Section

// This code iteratively cycles the variable inside each result
// the nodeName is the variable name


parsedResponse.put(new String("numResults"),
numResults.toString());
int resultNumber = 0;
NodeList results = resultsElement.getElementsByTagName("result");
for (int i = 0; i < numResults; i++){
Element result = (Element) results.item(i);
NodeList resultItem = result.getChildNodes();
resultNumber = i + 1;
for (int j = 0; j < resultItem.getLength(); j++){
Element resultValue = (Element) resultItem.item(j);
parsedResponse.put(new Integer(resultNumber).toString() + "-"
+ resultValue.getNodeName(),
resultValue.getFirstChild().getNodeValue());
}

}


return parsedResponse;
}


}


The PHP code:
<?php
header('Content-type: application/xml');
echo "<?xml version='1.0' encoding='UTF-8'?>
<begaga>
<errors num_errors='0'>
</errors>
<results num_results='1'>
<result>
<user_ID><![CDATA[119]]></user_ID>
<uSERNAme><![CDATA['m...@here.com']]></uSERNAme>
<first_name><![CDATA[Nuno]]></first_name>
<last_name><![CDATA[ME]]></last_name>
<nickname><![CDATA[Not ME]]></nickname>
<user_level><![CDATA[99]]></user_level>
<anti_phishing_image><![CDATA[that.png]]></anti_phishing_image>
<return_message><![CDATA[Ok!]]></return_message>
</result>
</results>
</begaga>";

?>

Problem 1:
Using content-type: text/xml or application/xml:
In FF the content of event.getResults() is Null
In IE the content of event.getResults() is mess with the XML being
wrapped in HTML:


<DIV class=e><SPAN class=b>&nbsp;</SPAN> <SPAN class=m>&lt;?</
SPAN><SPAN class=pi>xml version="1.0" encoding="UTF-8" </SPAN><SPAN
class=m>?&gt;</SPAN> </DIV>
<DIV class=e>
<DIV class=c style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em"><A class=b
onfocus=h() onclick="return false" href="#">-</A> <SPAN class=m>&lt;</
SPAN><SPAN class=t>begaga</SPAN><SPAN class=m>&gt;</SPAN></DIV>
<DIV>
<DIV class=e>
<DIV style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em"><SPAN class=b>&nbsp;</
SPAN> <SPAN class=m>&lt;</SPAN><SPAN class=t>errors</SPAN> <SPAN
class=t>num_errors</SPAN><SPAN class=m>="</SPAN><B>0</B><SPAN
class=m>"</SPAN><SPAN class=m> /&gt;</SPAN> </DIV></DIV>
<DIV class=e>
<DIV class=c style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em"><A class=b
onfocus=h() onclick="return false" href="#">-</A> <SPAN class=m>&lt;</
SPAN><SPAN class=t>results</SPAN><SPAN class=t> num_results</
SPAN><SPAN class=m>="</SPAN><B>1</B><SPAN class=m>"</SPAN><SPAN
class=m>&gt;</SPAN></DIV>
<DIV>
<DIV class=e>
<DIV class=c style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em"><A class=b
onfocus=h() onclick="return false" href="#">-</A> <SPAN class=m>&lt;</
SPAN><SPAN class=t>result</SPAN><SPAN class=m>&gt;</SPAN></DIV>
<DIV>
<DIV class=e>
<DIV class=c><A class=b onfocus=h() onclick="return false" href="#">-</
A> <SPAN class=m>&lt;</SPAN><SPAN class=t>user_ID</SPAN><SPAN
class=m>&gt;</SPAN></DIV>
<DIV>
<DIV class=k><SPAN><A class=b style="VISIBILITY: hidden" onfocus=h()
onclick="return false">-</A> <SPAN class=m>&lt;![CDATA[</SPAN></SPAN>
<SPAN class=di id=""><PRE>119</PRE></SPAN><SPAN class=b>&nbsp;</SPAN>
<SPAN class=m>]]&gt;</SPAN>
<SCRIPT>f(clean);</SCRIPT>
</DIV>
<DIV><SPAN class=b>&nbsp;</SPAN> <SPAN class=m>&lt;/</SPAN><SPAN
class=t>user_ID</SPAN><SPAN class=m>&gt;</SPAN></DIV></DIV></DIV>
<DIV class=e>
<DIV class=c><A class=b onfocus=h() onclick="return false" href="#">-</
A> <SPAN class=m>&lt;</SPAN><SPAN class=t>uSERNAme</SPAN><SPAN
class=m>&gt;</SPAN></DIV>
<DIV>
<DIV class=k><SPAN><A class=b style="VISIBILITY: hidden" onfocus=h()
onclick="return false">-</A> <SPAN class=m>&lt;![CDATA[</SPAN></SPAN>
<SPAN class=di id=""><PRE>'m...@here.com'</PRE></SPAN><SPAN
class=b>&nbsp;</SPAN> <SPAN class=m>]]&gt;</SPAN>
<SCRIPT>f(clean);</SCRIPT>
</DIV>
<DIV><SPAN class=b>&nbsp;</SPAN> <SPAN class=m>&lt;/</SPAN><SPAN
class=t>uSERNAme</SPAN><SPAN class=m>&gt;</SPAN></DIV></DIV></DIV>
<DIV class=e>
<DIV class=c><A class=b onfocus=h() onclick="return false" href="#">-</
A> <SPAN class=m>&lt;</SPAN><SPAN class=t>first_name</SPAN><SPAN
class=m>&gt;</SPAN></DIV>
<DIV>
<DIV class=k><SPAN><A class=b style="VISIBILITY: hidden" onfocus=h()
onclick="return false">-</A> <SPAN class=m>&lt;![CDATA[</SPAN></SPAN>
<SPAN class=di id=""><PRE>Nuno</PRE></SPAN><SPAN class=b>&nbsp;</SPAN>
<SPAN class=m>]]&gt;</SPAN>
<SCRIPT>f(clean);</SCRIPT>
</DIV>
<DIV><SPAN class=b>&nbsp;</SPAN> <SPAN class=m>&lt;/</SPAN><SPAN
class=t>first_name</SPAN><SPAN class=m>&gt;</SPAN></DIV></DIV></DIV>
<DIV class=e>
<DIV class=c><A class=b onfocus=h() onclick="return false" href="#">-</
A> <SPAN class=m>&lt;</SPAN><SPAN class=t>last_name</SPAN><SPAN
class=m>&gt;</SPAN></DIV>
<DIV>
<DIV class=k><SPAN><A class=b style="VISIBILITY: hidden" onfocus=h()
onclick="return false">-</A> <SPAN class=m>&lt;![CDATA[</SPAN></SPAN>
<SPAN class=di id=""><PRE>ME</PRE></SPAN><SPAN class=b>&nbsp;</SPAN>
<SPAN class=m>]]&gt;</SPAN>
<SCRIPT>f(clean);</SCRIPT>
</DIV>
<DIV><SPAN class=b>&nbsp;</SPAN> <SPAN class=m>&lt;/</SPAN><SPAN
class=t>last_name</SPAN><SPAN class=m>&gt;</SPAN></DIV></DIV></DIV>
<DIV class=e>
<DIV class=c><A class=b onfocus=h() onclick="return false" href="#">-</
A> <SPAN class=m>&lt;</SPAN><SPAN class=t>nickname</SPAN><SPAN
class=m>&gt;</SPAN></DIV>
<DIV>
<DIV class=k><SPAN><A class=b style="VISIBILITY: hidden" onfocus=h()
onclick="return false">-</A> <SPAN class=m>&lt;![CDATA[</SPAN></SPAN>
<SPAN class=di id=""><PRE>Not ME</PRE></SPAN><SPAN class=b>&nbsp;</
SPAN> <SPAN class=m>]]&gt;</SPAN>
<SCRIPT>f(clean);</SCRIPT>
</DIV>
<DIV><SPAN class=b>&nbsp;</SPAN> <SPAN class=m>&lt;/</SPAN><SPAN
class=t>nickname</SPAN><SPAN class=m>&gt;</SPAN></DIV></DIV></DIV>
<DIV class=e>
<DIV class=c><A class=b onfocus=h() onclick="return false" href="#">-</
A> <SPAN class=m>&lt;</SPAN><SPAN class=t>user_level</SPAN><SPAN
class=m>&gt;</SPAN></DIV>
<DIV>
<DIV class=k><SPAN><A class=b style="VISIBILITY: hidden" onfocus=h()
onclick="return false">-</A> <SPAN class=m>&lt;![CDATA[</SPAN></SPAN>
<SPAN class=di id=""><PRE>99</PRE></SPAN><SPAN class=b>&nbsp;</SPAN>
<SPAN class=m>]]&gt;</SPAN>
<SCRIPT>f(clean);</SCRIPT>
</DIV>
<DIV><SPAN class=b>&nbsp;</SPAN> <SPAN class=m>&lt;/</SPAN><SPAN
class=t>user_level</SPAN><SPAN class=m>&gt;</SPAN></DIV></DIV></DIV>
<DIV class=e>
<DIV class=c><A class=b onfocus=h() onclick="return false" href="#">-</
A> <SPAN class=m>&lt;</SPAN><SPAN class=t>anti_phishing_image</
SPAN><SPAN class=m>&gt;</SPAN></DIV>
<DIV>
<DIV class=k><SPAN><A class=b style="VISIBILITY: hidden" onfocus=h()
onclick="return false">-</A> <SPAN class=m>&lt;![CDATA[</SPAN></SPAN>
<SPAN class=di id=""><PRE>that.png</PRE></SPAN><SPAN class=b>&nbsp;</
SPAN> <SPAN class=m>]]&gt;</SPAN>
<SCRIPT>f(clean);</SCRIPT>
</DIV>
<DIV><SPAN class=b>&nbsp;</SPAN> <SPAN class=m>&lt;/</SPAN><SPAN
class=t>anti_phishing_image</SPAN><SPAN class=m>&gt;</SPAN></DIV></
DIV></DIV>
<DIV class=e>
<DIV class=c><A class=b onfocus=h() onclick="return false" href="#">-</
A> <SPAN class=m>&lt;</SPAN><SPAN class=t>return_message</SPAN><SPAN
class=m>&gt;</SPAN></DIV>
<DIV>
<DIV class=k><SPAN><A class=b style="VISIBILITY: hidden" onfocus=h()
onclick="return false">-</A> <SPAN class=m>&lt;![CDATA[</SPAN></SPAN>
<SPAN class=di id=""><PRE>Ok!</PRE></SPAN><SPAN class=b>&nbsp;</SPAN>
<SPAN class=m>]]&gt;</SPAN>
<SCRIPT>f(clean);</SCRIPT>
</DIV>
<DIV><SPAN class=b>&nbsp;</SPAN> <SPAN class=m>&lt;/</SPAN><SPAN
class=t>return_message</SPAN><SPAN class=m>&gt;</SPAN></DIV></DIV></
DIV>
<DIV><SPAN class=b>&nbsp;</SPAN> <SPAN class=m>&lt;/</SPAN><SPAN
class=t>result</SPAN><SPAN class=m>&gt;</SPAN></DIV></DIV></DIV>
<DIV><SPAN class=b>&nbsp;</SPAN> <SPAN class=m>&lt;/</SPAN><SPAN
class=t>results</SPAN><SPAN class=m>&gt;</SPAN></DIV></DIV></DIV>
<DIV><SPAN class=b>&nbsp;</SPAN> <SPAN class=m>&lt;/</SPAN><SPAN
class=t>begaga</SPAN><SPAN class=m>&gt;</SPAN></DIV></DIV></DIV>


Using content-type: text/html:
In FF the content of event.getResults() is:

(Notice the -- added at the beginning and end of the CDATA code and
user_id is now in lowercase )

<begaga> <errors num_errors="0"> </errors> <results
num_results="1"> <result> <user_id><!--[CDATA[119]]--></user_id>
<username><!--[CDATA['m...@here.com']]--></username> <first_name><!--
[CDATA[Nuno]]--></first_name> <last_name><!--[CDATA[ME]]--></
last_name> <nickname><!--[CDATA[Not ME]]--></nickname>
<user_level><!--[CDATA[99]]--></user_level> <anti_phishing_image><!--
[CDATA[that.png]]--></anti_phishing_image> <return_message><!--
[CDATA[Ok!]]--></return_message> </result> </results> </begaga>
Plain script result:



Inside parsing function:


Parsed Results:

{numErrors=0, numResults=1, 1-user_id=[CDATA[119]], 1-
username=[CDATA['m...@here.com']], 1-first_name=[CDATA[Nuno]], 1-
last_name=[CDATA[ME]], 1-nickname=[CDATA[Not ME]], 1-
user_level=[CDATA[99]], 1-anti_phishing_image=[CDATA[that.png]], 1-
return_message=[CDATA[Ok!]]}



In IE the content of event.getResults() does the same mess.

I have found another POST with a similar problem but the IE wasn't
that messed up:
http://groups.google.co.uk/group/Google-Web-Toolkit/browse_thread/thread/d754099023b8d40e/98b7c22317d6e12a?hl=en&lnk=gst&q=formpanel+XML#98b7c22317d6e12a

Do you have any idea what this problem might be?

I really need to use FormPanel instead of the XMLHTTPRequest because
some of the forms have file upload and those also receive XML for
error reporting from the server!

Thanks for the help,

Nuno




On 29 May, 22:18, Peter Blazejewicz <peter.blazejew...@gmail.com>
wrote:

Thomas Broyer

unread,
May 31, 2008, 2:21:49 PM5/31/08
to Google Web Toolkit


On May 31, 1:25 pm, nuno <nba...@gmail.com> wrote:
> Hi Peter,
>
> Thanks for your reply but I was referring to an XML being returned as
> response to a formPanel. (I know my first post was totally unclear,
> sorry)
>
> Starting again:
>
> I have a LAMP server and I am using a FormPanel to send information
> for the server and process an XML response. I now found that my
> problems are bigger than just the uppercase issue.
> I now think that IE and FF are playing games with me.

For FormPanel to work correctly, you should send data as text/html
(and getResult() returns the body.innerHTML). If you want to send XML,
I'd suggest sending HTML-escaped XML (i.e. &lt;root/> instead of <root/
>) and an XML parser on the client-side. That's a bit "hackish", but
"the Web's like that" ;-)

nuno

unread,
Jun 1, 2008, 10:26:08 AM6/1/08
to Google Web Toolkit
Brilliant Thomas,

Thanks it worked.

Cheers,

Nuno
Reply all
Reply to author
Forward
0 new messages