title: Java XML String with attributes to NodeList (parsing)
body: <p>I have a string, whose contents is an XML document.</p>
  
  <p>Here is an example of a string.</p>
  
  <pre><code>String xmlContent = "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;" + 
  "&lt;Service oem=\"myOem\" agent=\"myAgent\" version=\"0.5.5.0\" build=\"30-01-2014-11-46\" /&gt;";
  </code></pre>
  
  <p>I want to convert this string to a NodeList. A Google search led to this <a href="http://itjbg.wordpress.com/2012/07/14/parse-xml-string-using-dom-and-stringreader-in-java/" rel="nofollow">article</a>.</p>
  
  <p>I tried the following code:</p>
  
  <pre><code>DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
  InputSource is = new InputSource();
  is.setCharacterStream(new StringReader(xmlContent));
  Document doc = db.parse(is);
  NodeList oNodeService = doc.getElementsByTagName("Service");
  </code></pre>
  
  <p>The problem is that I get a rip on the "db.parse(is)" line. The problem seems to be that this method does not support XML attrihutes.</p>
  
  <p>The error message is:</p>
  
  <pre><code>[Fatal Error] :1:70: Element type "Service" must be followed by either attribute specifications, "&gt;" or "/&gt;".
  org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 70; Element type "Service" must be followed by either attribute specifications, "&gt;" or "/&gt;".
      at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
      at PkgNetAccelerator32.MainEvents.ShowHtsInfo(MainEvents.java:1575)
  </code></pre>
  
  <p>How can I successfully convert this XML string to a NodeList?</p>
  
  <p>UPDATE:
  Hmm, the failure is specific to the XML string. I gave a shortened version above. I removed all attributes that cause no crashes.</p>
  
  <pre><code>String xmlContent = "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;&lt;Service hostname=\"sarah-linux.localdomain\"uname=\"Linux sarah-linux.localdomain 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux\" /&gt;";
  </code></pre>
  
  <p>If I were to hazard a guess, I would say it is the period or the dash. I wanted to get this update in first.</p>