Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to iterate through the org.w3c.dom.NodeList using jython?
    primarykey
    data
    text
    <p>I'm using org.w3c.dom to process some xml documents. And I'm using jython 2.5.1 to implement it.</p> <p>Part of my xml document (EmployeeInfo.xml) is like:</p> <pre><code>&lt;employees&gt; &lt;employee id="1"&gt; &lt;name&gt;ABC&lt;/name&gt; &lt;title&gt;Software Engineer&lt;/title&gt; &lt;/employee&gt; &lt;employee id="2"&gt; &lt;name&gt;DEF&lt;/name&gt; &lt;title&gt;Systems Engineer&lt;/title&gt; &lt;/employee&gt; &lt;employee id="3"&gt; &lt;name&gt;GHI&lt;/name&gt; &lt;title&gt;QA Engineer&lt;/title&gt; &lt;/employee&gt; ...... &lt;/employees&gt; </code></pre> <p>And my jython code for reading in and parsing xml is like:</p> <pre><code>import sys, logging logging.basicConfig(level=logging.INFO) from java.io import File from javax.xml.parsers import DocumentBuilder from javax.xml.parsers import DocumentBuilderFactory from org.w3c.dom import Document from org.w3c.dom import Element from org.w3c.dom import Node from org.w3c.dom import NodeList // ... some code file = "C:/Users/Adminstrator/Doc/EmployeeInfo.xml" doc = File(file) if doc.exists(): docFactory = DocumentBuilderFactory.newInstance() docFactory.setNamespaceAware(True) docBuilder = docFactory.newDocumentBuilder() if doc.endswith(".xml"): logging.info(" -- Reading " + doc) employeeDoc = docBuilder.parse(doc) if employeeDoc != None: employees = employeeDoc.getElementsByTagNameNS("*","employee") if employees != None: for employee in employees: logging.info(employee.getChildNodes().getLength()) else: logging.warn("Failed to get the employee from " + doc) else: logging.warn("Failed to parse the document " + doc) else: logging.warn("Failed to find the specified document" + doc + ", please check the path!") </code></pre> <p>When I ran this script, there was an error:</p> <pre><code>TypeError: 'org.apache.xerces.dom.DeepNodeListImpl' object is not iterable </code></pre> <p>referring to the line:</p> <pre><code>for employee in employees: </code></pre> <p>It seems like it automatically treat the 'employees' as the jython's NodeList rather than org.w3c.dom.NodeList...</p> <p>I searched online regarding this issue, but I've got little regarding this issue...Could anyone here help me with this? Thanks in advance! </p>
    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. 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