Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 613777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:02:26+00:00 2026-05-13T18:02:26+00:00

I load xml file into DOM model and analyze it. The code for that

  • 0

I load xml file into DOM model and analyze it.

The code for that is:

public class MyTest {
public static void main(String[] args) {        
    Document doc = XMLUtils.fileToDom("MyTest.xml");//Loads xml data to DOM
    Element rootElement = doc.getDocumentElement();
    NodeList nodes = rootElement.getChildNodes();
    Node child1 = nodes.item(1);
    Node child2 = nodes.item(3);
    String str1 = child1.getTextContent();
    String str2 = child2.getTextContent();      
    if(str1 != null){
        System.out.println(str1.equals(str2));
    }
    System.out.println();
    System.out.println(str1);
    System.out.println(str2);
}   

}

MyTest.xml

<tests>
   <test name="1">ff1 &quot;</test>
   <test name="2">ff1 "</test>
</tests>

Result:

true

ff1 "
ff1 "

Desired result:

false

ff1 &quot;
ff1 "

So I need to distinguish these two cases: when the quote is escaped and is not.

Please help.

Thank you in advance.

P.S. The code for XMLUtils#fileToDom(String filePath), a snippet from XMLUtils class:

static {
    DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
    dFactory.setNamespaceAware(false);
    dFactory.setValidating(false);
    try {
        docNonValidatingBuilder = dFactory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
    }
}

public static DocumentBuilder getNonValidatingBuilder() {
    return docNonValidatingBuilder;
}

public static Document fileToDom(String filePath) {

    Document doc = getNonValidatingBuilder().newDocument();
    File f = new File(filePath);
    if(!f.exists())
        return doc;

    try {
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        DOMResult result = new DOMResult(doc);
        StreamSource source = new StreamSource(f);
        transformer.transform(source, result);
    } catch (Exception e) {
        return doc;
    }

    return doc;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:02:26+00:00Added an answer on May 13, 2026 at 6:02 pm

    I’ve take a look on source code of apache xerces and propose my solution (but it is monkey patch).
    I’ve wrote simple class

    package a;
    import java.io.IOException;
    import org.apache.xerces.impl.XMLDocumentScannerImpl;
    import org.apache.xerces.parsers.NonValidatingConfiguration;
    import org.apache.xerces.xni.XMLString;
    import org.apache.xerces.xni.XNIException;
    import org.apache.xerces.xni.parser.XMLComponent;
    
    public class MyConfig extends NonValidatingConfiguration {
    
        private MyScanner myScanner;
    
        @Override
        @SuppressWarnings("unchecked")
        protected void configurePipeline() {
            if (myScanner == null) {
                myScanner = new MyScanner();
                addComponent((XMLComponent) myScanner);
            }
            super.fProperties.put(DOCUMENT_SCANNER, myScanner);
            super.fScanner = myScanner;
            super.fScanner.setDocumentHandler(this.fDocumentHandler);
            super.fLastComponent = fScanner;
        }
    
        private static class MyScanner extends XMLDocumentScannerImpl {
    
            @Override
            protected void scanEntityReference() throws IOException, XNIException {
                // name
                String name = super.fEntityScanner.scanName();
                if (name == null) {
                    reportFatalError("NameRequiredInReference", null);
                    return;
                }
    
                super.fDocumentHandler.characters(new XMLString(("&" + name + ";")
                    .toCharArray(), 0, name.length() + 2), null);
    
                // end
                if (!super.fEntityScanner.skipChar(';')) {
                    reportFatalError("SemicolonRequiredInReference",
                            new Object[] { name });
                }
                fMarkupDepth--;
            }
        }
    
    }
    

    You need to add only next line to your main method before start parsing

    System.setProperty(
                "org.apache.xerces.xni.parser.XMLParserConfiguration",
                "a.MyConfig");
    

    And you will have expected result:

    false
    
    ff1 &quot;
    ff1 "
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 320k
  • Answers 320k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer They take parameters and return a result depending on those… May 14, 2026 at 12:24 am
  • Editorial Team
    Editorial Team added an answer When are you wanting the callback function to be fired?… May 14, 2026 at 12:24 am
  • Editorial Team
    Editorial Team added an answer I'm not aware of any means by which to control… May 14, 2026 at 12:24 am

Related Questions

I have what I thought was a relatively easy Ajax/animation that I'm adding to
I was trying to insert new data into an existing XML file, but it's
Im using Python's built in XML parser to load a 1.5 gig XML file
I'm receiving XML over a network socket. I need to take that XML and
I've been trying to parse this feed . If you click on that link,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.