in python, how do i refer to an xml tag that contains a hyphen

  • Last Update :
  • Techknowledgy :

Instead, use soup.find() or soup.find_all():

>>> from bs4 import BeautifulSoup
>>> soup = BeautifulSoup('<thing>
>>> soup.thing
>>> soup.distribution-code
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
      NameError: name 'code' is not defined
      >>> soup.find('distribution-code')

Suggestion : 2

An element name can contain any alphanumeric characters. The only punctuation mark allowed in names are the hyphen (-), under-score (_) and period (.).,element-name is the name of the element. The name its case in the start and end tags must match.,Each XML document contains one or more elements, the scope of which are either delimited by start and end tags, or for empty elements, by an empty-element tag.,XML elements can be defined as building blocks of an XML. Elements can behave as containers to hold text, elements, attributes, media objects or all of these.

Following is the syntax to write an XML element −

<element-name attribute1 attribute2>
  • element-name is the name of the element. The name its case in the start and end tags must match.

  • attribute1, attribute2 are attributes of the element separated by white spaces. An attribute defines a property of the element. It associates a name with a value, which is a string of characters. An attribute is written as −

name = "value"

An empty element (element with no content) has following syntax −

<name attribute1 attribute2... />

Suggestion : 3

Last Updated : 24 May, 2022


<element-name attributes> Contents...</element-name>


name = "Geeks"
Here, Geeks represents the value of attribute

Empty Elements: An element in XML document which does not contains the content is known as Empty Element. The basic syntax of empty element in XML as follows:

<elements-name attributename />

Suggestion : 4


   <CATEGORY name="category display name" refname="category reference name">
      <DEFAULTWORKITEMTYPE name="work item type reference name" />
      <WORKITEMTYPE name="work item type reference name" />