title: Why getting null node value while parsing XML
body: <p>While parsing the below XML .First <code>url-malformed-exception</code> was coming while parsing so in the code instead of giving the xml String i used this code</p>
  
  <pre><code>Document doc=dBuilder.parse(newInputSource(newByteArrayInputStream(xmlResponse.getBytes("utf-8"))));
  </code></pre>
  
  <p>according to this link </p>
  
  <p><a href="https://stackoverflow.com/questions/1706493/java-net-malformedurlexception-no-protocol">java.net.MalformedURLException: no protocol</a> </p>
  
  <p>now i am getting the node value as null .<strong><em>How can i overcome this .In the code in for loop i have mentioned where the null value for node is coming</em></strong></p>
  
  <p>i am using following code:</p>
  
  <pre><code>try {
      DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
      Document doc = dBuilder.parse(new InputSource(new ByteArrayInputStream(xmlResponse.getBytes("utf-8"))));
      //read this - https://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
      doc.getDocumentElement().normalize();
      System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
      XPath xPath =  XPathFactory.newInstance().newXPath()
      String expression = "/GetMatchingProductForIdResponse/GetMatchingProductForIdResult/Products/Product"
      System.out.println(expression)
      NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(doc, XPathConstants.NODESET)
      System.out.println("the size will be of the node list ${nodeList.getLength()}");
      for (int i = 0; i &lt; nodeList.getLength(); i++) {
              System.out.println(nodeList.item(i).getNodeValue()+"the value coming will be "); // here i am getting value null for each node
      }
  } catch (Exception e) {
      e.printStackTrace(System.out);
  }
  </code></pre>
  
  <p>to parse the XML:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;GetMatchingProductForIdResponse   xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01"&gt;
    &lt;GetMatchingProductForIdResult Id="H5-9OSH-9NZ7" IdType="SellerSKU" status="Success"&gt;
      &lt;Products xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01" xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd"&gt;
      &lt;Product&gt;
        &lt;Identifiers&gt;
          &lt;MarketplaceASIN&gt;
            &lt;MarketplaceId&gt;ATVPDKIKX0DER&lt;/MarketplaceId&gt;
            &lt;ASIN&gt;B004FQLAH2&lt;/ASIN&gt;
          &lt;/MarketplaceASIN&gt;
        &lt;/Identifiers&gt;
        &lt;AttributeSets&gt;
          &lt;ns2:ItemAttributes xml:lang="en-US"&gt;
            &lt;ns2:Binding&gt;Office Product&lt;/ns2:Binding&gt;
            &lt;ns2:Brand&gt;Konica-Minolta&lt;/ns2:Brand&gt;
            &lt;ns2:Color&gt;Y&lt;/ns2:Color&gt;
            &lt;ns2:CPUSpeed Units="MHz"&gt;200&lt;/ns2:CPUSpeed&gt;
            &lt;ns2:Department&gt;Printers&lt;/ns2:Department&gt;
            &lt;ns2:Feature&gt;Amp Up your Output - The magicolor 3730DN business color laser printer outputs at speeds up to 25 ppm in both color and B&amp;W which means you can keep up in just about any business environment.&lt;/ns2:Feature&gt;
            &lt;ns2:Feature&gt;Unparalleled Image Quality - High resolution 2400 (equivalent) x 600 dpi printing for great color and clarity in both images and text.&lt;/ns2:Feature&gt;
            &lt;ns2:Feature&gt;Happy Planet, Outstanding Printing - Simitri HD Toner with Biomass allows for outstanding printing with the environment in mind.&lt;/ns2:Feature&gt;
            &lt;ns2:Feature&gt;Connect quicker - Why wait? Standard Ethernet and high-speed USB 2.0 gets you connected faster than ever before.Specifications&lt;/ns2:Feature&gt;
            &lt;ns2:Feature&gt;Type - Full-Color Laser Printer&lt;/ns2:Feature&gt;
            &lt;ns2:ItemDimensions&gt;
              &lt;ns2:Height Units="inches"&gt;13.62&lt;/ns2:Height&gt;
              &lt;ns2:Length Units="inches"&gt;20.47&lt;/ns2:Length&gt;
              &lt;ns2:Width Units="inches"&gt;16.50&lt;/ns2:Width&gt;
              &lt;ns2:Weight Units="pounds"&gt;56.22&lt;/ns2:Weight&gt;
            &lt;/ns2:ItemDimensions&gt;
            &lt;ns2:IsAutographed&gt;false&lt;/ns2:IsAutographed&gt;
            &lt;ns2:IsMemorabilia&gt;false&lt;/ns2:IsMemorabilia&gt;
            &lt;ns2:Label&gt;Konica&lt;/ns2:Label&gt;
            &lt;ns2:ListPrice&gt;
              &lt;ns2:Amount&gt;449.00&lt;/ns2:Amount&gt;
              &lt;ns2:CurrencyCode&gt;USD&lt;/ns2:CurrencyCode&gt;
            &lt;/ns2:ListPrice&gt;
            &lt;ns2:Manufacturer&gt;Konica&lt;/ns2:Manufacturer&gt;
            &lt;ns2:Model&gt;A0VD017&lt;/ns2:Model&gt;
            &lt;ns2:NumberOfItems&gt;1&lt;/ns2:NumberOfItems&gt;
            &lt;ns2:OperatingSystem&gt;Windows XP, Vista, 7&lt;/ns2:OperatingSystem&gt;
            &lt;ns2:OperatingSystem&gt;Mac X 10.2.8, 10.6+&lt;/ns2:OperatingSystem&gt;
            &lt;ns2:PackageDimensions&gt;
              &lt;ns2:Height Units="inches"&gt;19.00&lt;/ns2:Height&gt;
              &lt;ns2:Length Units="inches"&gt;24.20&lt;/ns2:Length&gt;
              &lt;ns2:Width Units="inches"&gt;22.00&lt;/ns2:Width&gt;
              &lt;ns2:Weight Units="pounds"&gt;65.30&lt;/ns2:Weight&gt;
            &lt;/ns2:PackageDimensions&gt;
            &lt;ns2:PackageQuantity&gt;1&lt;/ns2:PackageQuantity&gt;
            &lt;ns2:PartNumber&gt;A0VD017&lt;/ns2:PartNumber&gt;
            &lt;ns2:ProductGroup&gt;CE&lt;/ns2:ProductGroup&gt;
            &lt;ns2:ProductTypeName&gt;PRINTER&lt;/ns2:ProductTypeName&gt;
            &lt;ns2:Publisher&gt;Konica&lt;/ns2:Publisher&gt;
            &lt;ns2:SmallImage&gt;
              &lt;ns2:URL&gt;http://ecx.images-amazon.com/images/I/21qN3BU-BHL._SL75_.jpg&lt;/ns2:URL&gt;
              &lt;ns2:Height Units="pixels"&gt;75&lt;/ns2:Height&gt;
              &lt;ns2:Width Units="pixels"&gt;75&lt;/ns2:Width&gt;
            &lt;/ns2:SmallImage&gt;
            &lt;ns2:Studio&gt;Konica&lt;/ns2:Studio&gt;
            &lt;ns2:Title&gt;Konica Minolta Magicolor 3730DN Color Laser Printer 24PPM 2400X600DPI ENET USB 2.0&lt;/ns2:Title&gt;
          &lt;/ns2:ItemAttributes&gt;
        &lt;/AttributeSets&gt;
        &lt;Relationships/&gt;
        &lt;SalesRankings/&gt;
      &lt;/Product&gt;
      &lt;/Products&gt;
    &lt;/GetMatchingProductForIdResult&gt;
    &lt;ResponseMetadata&gt;
      &lt;RequestId&gt;0b508338-3afe-4178-adc4-60c9c8448987&lt;/RequestId&gt;
    &lt;/ResponseMetadata&gt;
  &lt;/GetMatchingProductForIdResponse&gt;
  </code></pre>