title: White Space in XML
body: <p>I am trying to work with an xml file from SBA api.</p>
  
  <blockquote>
    <p><a href="http://api.sba.gov/loans_grants/federal_and_state_financing_for/ny.xml" rel="nofollow">http://api.sba.gov/loans_grants/federal_and_state_financing_for/ny.xml</a></p>
  </blockquote>
  
  <p>The problem is when I try to parse this xml with xpath I get this error:</p>
  
  <blockquote>
    <p>[Fatal Error] loans_grants.dtd:3:22: White space is required before
    the attribute type in the declaration of attribute "CDATA" for element
    "count". Exception in thread "main" org.xml.sax.SAXParseException:
    White space is required before the attribute type in the declaration
    of attribute "CDATA" for element "count".</p>
  </blockquote>
  
  <p>After observing the xml file I think the problem is in following lines and similar lines after that:</p>
  
  <p><code>&lt;grant_loans count="103"&gt;</code></p>
  
  <p><code>&lt;industry nil="true"/&gt;</code></p>
  
  <p><code>&lt;state_name nil="true"/&gt;</code></p>
  
  <p>I think if there were space between <code>count</code> and <code>"103"</code> and <code>nil</code> and <code>"true"</code> then this error would not happen. As the whole xml is too big I copied some portion of it and made these changes and saved in my local storage. Then I could run and parse it without error. I just put some spaces like this:</p>
  
  <pre><code>&lt;grant_loans count = "103"&gt;
  </code></pre>
  
  <p>How can I do this with my program to all places that requires space and then use that for further parsing?</p>
  
  <p>I can post my java code here if you need but that code is working for other xml files, so I think this xml file has the problem.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Java code segment:</p>
  
  <pre><code>DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      factory.setNamespaceAware(true);
      DocumentBuilder builder;
      Document doc = null;
      XPathExpression expr = null;
      builder = factory.newDocumentBuilder();
      doc = (Document) builder
              .parse("http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway&amp;sensor=false");
  
      // Create a XPathFactory
      XPathFactory xFactory = XPathFactory.newInstance();
  
      // Create a XPath object
      XPath xpath = xFactory.newXPath();
  
      // Compile the XPath expression
      expr = xpath.compile("//geometry/location/lat/text()");
      System.out.println("expr" + expr);
      // Run the query and get a nodeset
      Object result = expr.evaluate(doc, XPathConstants.NODESET);
  
      // Cast the result to a DOM NodeList
      NodeList nodes = (NodeList) result;
      for (int i = 0; i &lt; nodes.getLength(); i++) {
          System.out.println(nodes.item(i).getNodeValue());  
      }
  
                         //this works
  // 
  // some other code
  //
  builder = factory.newDocumentBuilder();
      url = "http://api.sba.gov/loans_grants/federal_and_state_financing_for/ny.xml";
      doc = builder.parse(url); // problem occurs here
      xFactory = XPathFactory.newInstance();
  
      // Create a XPath object
      xpath = xFactory.newXPath();
  
      // Compile the XPath expression
      expr = xpath.compile("//grant_loan/url/text()");
      result = expr.evaluate(doc, XPathConstants.NODESET);
  
      // Cast the result to a DOM NodeList
      nodes = (NodeList) result;
      for (int i = 0; i &lt; nodes.getLength(); i++) {
          System.out.println(nodes.item(i).getNodeValue());
      }
  
  //other stuffs
  </code></pre>