Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>getNamedItemNS takes the namespaceURI as its first parameter (i.e. <code>http://sample.com</code>), not the prefix (<code>log</code>).</p> <p><strong>Edit:</strong></p> <p>Here's a test case in full. This prints out "Attribute value is someWriter". Tested using Xerces as the XML library. Does this work for you? </p> <pre><code>import java.io.IOException; import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.InputSource; import org.xml.sax.SAXException; public class GetNamedItemNSTester { public static void main(String[] args) { new GetNamedItemNSTester(); } String xml = "&lt;xml xmlns:log=\"http://sample.com\"&gt;\n" + "\n" + "&lt;test log:writer=\"someWriter\" /&gt;\n" + "\n" + "&lt;/xml&gt;"; public GetNamedItemNSTester() { StringReader xmlReader = new StringReader(xml); try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new InputSource(xmlReader)); Element currentNode = (Element)doc.getElementsByTagName("test").item(0); String attributeValue = currentNode.getAttributes() .getNamedItemNS("http://sample.com", "writer").getNodeValue(); System.out.println("Attribute value is " + attributeValue); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { xmlReader.close(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload