Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to get the attributes from xml file?
    primarykey
    data
    text
    <p>My Xml File looks like this: </p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE pointList SYSTEM "point.dtd"&gt; &lt;pointList&gt; &lt;point unit="mm"&gt; &lt;x&gt;2&lt;/x&gt; &lt;y&gt;3&lt;/y&gt; &lt;/point&gt; &lt;point unit="cm"&gt; &lt;x&gt;9&lt;/x&gt; &lt;y&gt;3&lt;/y&gt; &lt;/point&gt; &lt;point unit="px"&gt; &lt;x&gt;4&lt;/x&gt; &lt;y&gt;7&lt;/y&gt; &lt;/point&gt; &lt;/pointList&gt; </code></pre> <p>When i try to get attributes of tag point: </p> <pre><code>import java.io.File; import java.io.IOException; 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.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; public class TryXml { public static void main (String [] args) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = null; Document doc = null; try { builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e){ System.out.println(e.getMessage()); } File f = new File("p1.xml"); try { doc=builder.parse(f); } catch (SAXException e){ e.printStackTrace(); } catch (IOException e){ e.printStackTrace(); } Element root = doc.getDocumentElement(); System.out.println(root.getTagName()); System.out.println("****************"); NodeList nList = root.getChildNodes(); for (int i=0;i&lt;nList.getLength();i++) { if(nList.item(i) instanceof Element) System.out.println(nList.item(i).getAttributes()); } } } </code></pre> <p>all i get is something like the address: </p> <pre><code>com.sun.org.apache.xerces.internal.dom.AttributeMap@3214512e com.sun.org.apache.xerces.internal.dom.AttributeMap@53ddbcb1 com.sun.org.apache.xerces.internal.dom.AttributeMap@28f337b </code></pre> <p>can anyone give me a hint on how to get the attributes of point and maybe other inner tags? </p>
    singulars
    1. This table or related slice is empty.
    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. 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