-2

Consider the following xml file (lieferungen2.xml):

<?xml version="1.0"?>
<lieferungen>
    <artikel id="1">
       <name>apple</name>
       <preis >2</preis>
       <lieferant>Friedman</lieferant>
    </artikel>
</lieferungen>

With the following code, I wanted to print "apple" to the command line:

import xml.dom.minidom 

dom = xml.dom.minidom.parse("lieferungen2.xml")

a = dom.getElementsByTagName("artikel")

num=0


while(True):

    if a[0].childNodes[num].nodeName != "name":
        num++
    else:
        break

print(a[0].childNodes[num].childNodes[0].nodeValue)

However, I get the following error message:

    num++
        ^
SyntaxError: invalid syntax

To me this syntax looks perfectly fine? What's wrong here?

steady_progress
  • 3,311
  • 10
  • 31
  • 62

2 Answers2

0

num++ is not valid Python code, it would be like this

num += 1
Pike D.
  • 671
  • 2
  • 11
  • 30
0

Python does not support x ++ to increase a variable by one.

Instead, you have to do x += 1.

So your code would be:

if a[0].childNodes[num].nodeName != "name":
    num += 1
else:
    break
Ben Stobbs
  • 422
  • 6
  • 14