DOM parser example


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
      - amp cannot be resolved
      - Syntax error on token ";", .

My XML looks like

<?xml version="1.0" encoding="UTF-8"?>
   <name type="first">Paula</name>
Please advise
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

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

gudii9Author Commented:
Yes java, let me try
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

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
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
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.

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
If your are coding an XML parsing , I'd recommend you to get familiar with all XML node types, and the CDATA as well.
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

From novice to tech pro — start learning today.