Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

escaped XML data writing/reading/parsing queries.

Thread view: 
Piper707@hotmail.com - 12 Dec 2005 05:15 GMT
Hi,

My <operator> tag in XML can take any of the following values:

"<", ">", and "<>"

I enter the data this way in the xml:

<operator>&lt;</operator>
<operator>&gt;</operator>

This works fine for the first two.

1) How do I enter "<>" as data in the xml document?  I tried
<operator>&gt;&lt;</operator>, but that only reads the first value,
i.e. "<".

2) After parsing the field, I need to match the data to the content of
an List, and return the matched index:

XML tag:
--------
<OPERATOR>&lt;</OPERATOR>

This is the method
------------------

List operatorList = Arrays.asList("<>", "&lt;&gt;", "&lt;" ,"<", "&gt;"
,">");

public void setOperator(String operator){
  System.out.println("operator sent" + " ----> " + operator);
  System.out.println("operator index" + " ----> " +
operatorList.indexOf(operator));
}

Method Output:
---------------

operator sent ----> <
operator index ----> -1

It is unable to find either "<" or ">" in my list, I can't understand
why?

3) However when I try this:

if(operator.equals("<"))
System.out.println("received <");

It prints out "received <" correctly.

Can someone please clarify?

Thank you,
Rohit.
Hiran Chaudhuri - 12 Dec 2005 23:05 GMT
> My <operator> tag in XML can take any of the following values:
> "<", ">", and "<>"
> I enter the data this way in the xml:
> <operator>&lt;</operator>
> <operator>&gt;</operator>
> <operator>&gt;&lt;</operator>

What you mention here is correct. Now how do you parse this xml document?

> It is unable to find either "<" or ">" in my list, I can't understand
> why?
[quoted text clipped - 4 lines]
>
> Can someone please clarify?

It seems your XML document is correct, and your parser does the right thing
to change the entity reference into the real character. In java you compare
the two strings (operator.equals("<")) and this is successful.

Now your problem might arise if the List.indexOf(...) method does not do a
string compare but a direct compare ( object1 == object2). If object1 is the
same instance as object2 the expression is true, but if you have two
instances the expression is false, even if the objects have the equal
content.

Hiran


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.