DOM parser example

Hi,

I am using DOM parser to print simple XML file

Eclipse thowing error at below line. How can i fix it. Please advise

 if (node instanceof Element && node.getNodeName().equalsIgnoreCase("name")) {
    // a child element to process
    Element child = (Element) node;


error says
Multiple markers at this line
      - Syntax error on token ";", delete
       this token
      - amp cannot be resolved to a
       variable
      - amp cannot be resolved
      - Syntax error on token ";", .
       expected


My XML looks like

<?xml version="1.0" encoding="UTF-8"?>
<Employee>
   <name type="first">Paula</name>
   <ssn>1225</ssn>
</Employee>
Please advise
LVL 7
gudii9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zc2Commented:
this is Java, not an XHTML embedded Javascript, right?
Then you don't need to escape the & character.
Replace the faulted string with:
 if (node instanceof Element && node.getNodeName().equalsIgnoreCase("name")) {

Open in new window

0
gudii9Author Commented:
Yes java, let me try
0
gurpsbassiCommented:
WTF
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

gudii9Author Commented:
what is difference between these two lines. It worked with  &&

  //if (node instanceof Element &amp;&amp; node.getNodeName().equalsIgnoreCase("name")) {
   if (node instanceof Element && node.getNodeName().equalsIgnoreCase("name")) {



please advise
0
CEHJCommented:
what is difference between these two lines. It worked with  &&

&amp; makes no sense in Java - that's why. It's an html/xml escaped form of what does work
0
zc2Commented:
in XML the characters "<", ">" and "&" are used in the mark up and have to be escaped in the form &entity_name;
So, if you write a JavaScript code inside a XHTML web page (without using the CDATA section) you have to escape those characters.
Another case, if you took your source sample from anywhere which previously was an XHTML page, the escaping might accidentally penetrate to the code text. This could happen because of a bug in the site and/or the browser. You need just get rid of that escaping or find   a more reliable way (such as zip archive, git, svn, etc) to download the source code than the web page's text.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gudii9Author Commented:
if you write a JavaScript code inside a XHTML web page (without using the CDATA section)

i have no idea what is CDATA. Probably i will open new question by closing this
0
zc2Commented:
If your are coding an XML parsing , I'd recommend you to get familiar with all XML node types, and the CDATA as well.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.