smartXML 1.0.1__tar.gz → 1.0.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,82 @@
1
+ Metadata-Version: 2.4
2
+ Name: smartXML
3
+ Version: 1.0.9
4
+ Summary: smartXML package enables you to read, search, manipulate, and write XML files with ease
5
+ Author-email: Dudu Arbel <duduarbel@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Changelog, https://github.com/duduarbel/smartXML/blob/main/changelog.md
8
+ Keywords: python,example
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3 :: Only
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Operating System :: OS Independent
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown
18
+ Requires-Dist: requests>=2.31
19
+ Provides-Extra: dev
20
+ Requires-Dist: pytest>=8.0; extra == "dev"
21
+ Requires-Dist: mypy>=1.8; extra == "dev"
22
+ Requires-Dist: ruff>=0.3; extra == "dev"
23
+
24
+ # smartXML
25
+
26
+ The **smartXML** package enables you to read, search, manipulate, and write XML files with ease.
27
+
28
+ The API is designed to be simple, but it will be enhanced according to usage and requests.
29
+ The package includes a `SmartXML` representing the XML file, and `ElementBase` representing each element in the XML tree
30
+ ### SmartXML:
31
+ - properties:
32
+ - `root`: the root element of the XML file
33
+ - `declaration`: the XML declaration (e.g., `<?xml version="1.0" encoding="UTF-8"?>`)
34
+ - methods:
35
+ - `read`: reads the XML file from the root element
36
+ - `write`: writes the XML to a file
37
+ - `find`: finds elements from the root element
38
+
39
+ ### ElementBase: (base class for Element, Comment, TextOnlyComment, CData, and Doctype)
40
+ - properties:
41
+ - `name`: the name of the element
42
+ - `parent`: the parent element
43
+ - methods:
44
+ - `find`: finds elements from the current element
45
+ - `remove`: removes the current element from its parent
46
+ - `comment_out`: comments out the current element
47
+ - `add_before`: adds an element before the current element
48
+ - `add_after`: adds an element after the current element
49
+ - `add_as_son_of`: adds an element as a son of the current element
50
+ - `set_as_parent_of`: sets the current element as the parent of another element
51
+ - `to_string`: converts the current element to a string
52
+
53
+
54
+ ### Usage Example
55
+
56
+ ```python
57
+ from pathlib import Path
58
+ from smartXML.xmltree import SmartXML, TextOnlyComment
59
+
60
+ input_file = Path('./example.xml')
61
+ xml = SmartXML(input_file)
62
+
63
+ firstName = xml.find('students|student|firstName', with_content='Bob')
64
+ bob = firstName.parent
65
+ bob.comment_out()
66
+ header = TextOnlyComment('Bob is out')
67
+ header.add_before(bob)
68
+
69
+ xml.write()
70
+ ```
71
+ result (example.xml):
72
+ ```xml
73
+ <students>
74
+ <!-- Bob is out -->
75
+ <!--
76
+ <student id="S002">
77
+ <firstName>Bob</firstName>
78
+ <lastName>Levi</lastName>
79
+ </student>
80
+ -->
81
+ </students>
82
+ ```
@@ -0,0 +1,59 @@
1
+ # smartXML
2
+
3
+ The **smartXML** package enables you to read, search, manipulate, and write XML files with ease.
4
+
5
+ The API is designed to be simple, but it will be enhanced according to usage and requests.
6
+ The package includes a `SmartXML` representing the XML file, and `ElementBase` representing each element in the XML tree
7
+ ### SmartXML:
8
+ - properties:
9
+ - `root`: the root element of the XML file
10
+ - `declaration`: the XML declaration (e.g., `<?xml version="1.0" encoding="UTF-8"?>`)
11
+ - methods:
12
+ - `read`: reads the XML file from the root element
13
+ - `write`: writes the XML to a file
14
+ - `find`: finds elements from the root element
15
+
16
+ ### ElementBase: (base class for Element, Comment, TextOnlyComment, CData, and Doctype)
17
+ - properties:
18
+ - `name`: the name of the element
19
+ - `parent`: the parent element
20
+ - methods:
21
+ - `find`: finds elements from the current element
22
+ - `remove`: removes the current element from its parent
23
+ - `comment_out`: comments out the current element
24
+ - `add_before`: adds an element before the current element
25
+ - `add_after`: adds an element after the current element
26
+ - `add_as_son_of`: adds an element as a son of the current element
27
+ - `set_as_parent_of`: sets the current element as the parent of another element
28
+ - `to_string`: converts the current element to a string
29
+
30
+
31
+ ### Usage Example
32
+
33
+ ```python
34
+ from pathlib import Path
35
+ from smartXML.xmltree import SmartXML, TextOnlyComment
36
+
37
+ input_file = Path('./example.xml')
38
+ xml = SmartXML(input_file)
39
+
40
+ firstName = xml.find('students|student|firstName', with_content='Bob')
41
+ bob = firstName.parent
42
+ bob.comment_out()
43
+ header = TextOnlyComment('Bob is out')
44
+ header.add_before(bob)
45
+
46
+ xml.write()
47
+ ```
48
+ result (example.xml):
49
+ ```xml
50
+ <students>
51
+ <!-- Bob is out -->
52
+ <!--
53
+ <student id="S002">
54
+ <firstName>Bob</firstName>
55
+ <lastName>Levi</lastName>
56
+ </student>
57
+ -->
58
+ </students>
59
+ ```
@@ -4,10 +4,10 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "smartXML"
7
- version = "1.0.1"
7
+ version = "1.0.9"
8
8
  description = "smartXML package enables you to read, search, manipulate, and write XML files with ease"
9
9
  readme = "README.md"
10
- requires-python = ">=3.10"
10
+ requires-python = ">=3.9"
11
11
  license = "MIT"
12
12
 
13
13
  authors = [
@@ -18,6 +18,7 @@ keywords = ["python", "example"]
18
18
  classifiers = [
19
19
  "Programming Language :: Python :: 3",
20
20
  "Programming Language :: Python :: 3 :: Only",
21
+ "Programming Language :: Python :: 3.9",
21
22
  "Programming Language :: Python :: 3.10",
22
23
  "Programming Language :: Python :: 3.11",
23
24
  "Programming Language :: Python :: 3.12",
@@ -28,6 +29,9 @@ dependencies = [
28
29
  "requests>=2.31",
29
30
  ]
30
31
 
32
+ [project.urls]
33
+ Changelog = "https://github.com/duduarbel/smartXML/blob/main/changelog.md"
34
+
31
35
  [project.optional-dependencies]
32
36
  dev = [
33
37
  "pytest>=8.0",
@@ -1,4 +1,5 @@
1
1
  from typing import Union
2
+ import warnings
2
3
 
3
4
  from ._elements_utils import (
4
5
  _find_one,
@@ -80,11 +81,21 @@ class ElementBase:
80
81
 
81
82
  def add_as_son_of(self, parent: "Element"):
82
83
  """Add this element as a son of the given parent element."""
84
+ warnings.warn(
85
+ "add_as_son_of() is deprecated and will be removed in version 1.1.0 . add_before() ot add_after() instead.",
86
+ category=DeprecationWarning,
87
+ stacklevel=2
88
+ )
83
89
  parent._sons.append(self)
84
90
  self._parent = parent
85
91
 
86
92
  def set_as_parent_of(self, son: "Element"):
87
93
  """Set this element as the parent of the given son element."""
94
+ warnings.warn(
95
+ "set_as_parent_of() is deprecated and will be removed in version 1.1.0 . add_before() ot add_after() instead.",
96
+ category=DeprecationWarning,
97
+ stacklevel=2
98
+ )
88
99
  self._sons.append(son)
89
100
  son._parent = self
90
101
 
@@ -190,7 +201,7 @@ class Element(ElementBase):
190
201
  children_str = "".join(son._to_string(index + 1, indentation) for son in self._sons)
191
202
 
192
203
  if children_str:
193
- result = f"{indent}{opening_tag}" f"{self.content}" f"{"\n"}" f"{children_str}{indent}{closing_tag}"
204
+ result = f"{indent}{opening_tag}{self.content}\n{children_str}{indent}{closing_tag}"
194
205
  else:
195
206
  result = f"{indent}{opening_tag}{self.content}{closing_tag}"
196
207
 
@@ -122,7 +122,7 @@ class SmartXML:
122
122
  self._tree, self._doctype = self._read(self._file_name)
123
123
 
124
124
  @property
125
- def tree(self) -> str:
125
+ def tree(self) -> ElementBase:
126
126
  """Get the root element of the XML tree."""
127
127
  return self._tree
128
128
 
@@ -149,10 +149,19 @@ class SmartXML:
149
149
  """
150
150
  Read and parse the XML file into an element tree.
151
151
  :param file_name: Path to the XML file
152
+ :raises:
153
+ TypeError: if file_name is not a pathlib.Path object
154
+ FileNotFoundError: if file_name does not exist
155
+ BadXMLFormat: if the XML format is invalid
152
156
  """
153
- self.read(file_name)
157
+ if not isinstance(file_name, Path):
158
+ raise TypeError("file_name must be a pathlib.Path object")
159
+ if not file_name.exists():
160
+ raise FileNotFoundError(f"File {file_name} does not exist")
154
161
 
155
- def _read(self, file_name: Path) -> tuple[Any, None] | tuple[Any, Any]:
162
+ self._tree, self._doctype = self._read(file_name)
163
+
164
+ def _read(self, file_name: Path) -> tuple[Any, Any]:
156
165
  self._file_name = file_name
157
166
  ready_nodes = {} # depth -> list of elements
158
167
  incomplete_nodes = []
@@ -264,10 +273,17 @@ class SmartXML:
264
273
  :param file_name: Path to the XML file, if None, overwrite the original file
265
274
  :param indentation: string used for indentation, default is tab character
266
275
  :return: XML string if file_name is None, else None
276
+ :raises:
277
+ ValueError: if file name is not specified
278
+ TypeError: if file_name is not a pathlib.Path object
279
+ FileNotFoundError: if file_name does not exist
267
280
  """
268
281
 
269
282
  if file_name:
270
283
  self._file_name = file_name
284
+ if not self._file_name:
285
+ raise ValueError("File name is not specified")
286
+
271
287
  with open(self._file_name, "w") as file:
272
288
  if self._declaration:
273
289
  file.write(f"<?xml {self._declaration}?>\n")
@@ -284,7 +300,7 @@ class SmartXML:
284
300
 
285
301
  def find(
286
302
  self,
287
- name: str = None,
303
+ name: str = "",
288
304
  only_one: bool = True,
289
305
  with_content: str = None,
290
306
  ) -> Element | list[Element] | None:
@@ -296,7 +312,10 @@ class SmartXML:
296
312
  :return: the elements found,
297
313
  if found, return the elements that match the last name in the path,
298
314
  if not found, return None if only_one is True, else return empty list
315
+ :raises:
316
+ ValueError: if neither name nor with_content is provided
317
+
299
318
  """
300
- if name is None and with_content is None:
319
+ if not name and with_content is None:
301
320
  raise ValueError("At least one search criteria must be provided")
302
321
  return self._tree.find(name, only_one, with_content)
@@ -0,0 +1,82 @@
1
+ Metadata-Version: 2.4
2
+ Name: smartXML
3
+ Version: 1.0.9
4
+ Summary: smartXML package enables you to read, search, manipulate, and write XML files with ease
5
+ Author-email: Dudu Arbel <duduarbel@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Changelog, https://github.com/duduarbel/smartXML/blob/main/changelog.md
8
+ Keywords: python,example
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3 :: Only
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Operating System :: OS Independent
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown
18
+ Requires-Dist: requests>=2.31
19
+ Provides-Extra: dev
20
+ Requires-Dist: pytest>=8.0; extra == "dev"
21
+ Requires-Dist: mypy>=1.8; extra == "dev"
22
+ Requires-Dist: ruff>=0.3; extra == "dev"
23
+
24
+ # smartXML
25
+
26
+ The **smartXML** package enables you to read, search, manipulate, and write XML files with ease.
27
+
28
+ The API is designed to be simple, but it will be enhanced according to usage and requests.
29
+ The package includes a `SmartXML` representing the XML file, and `ElementBase` representing each element in the XML tree
30
+ ### SmartXML:
31
+ - properties:
32
+ - `root`: the root element of the XML file
33
+ - `declaration`: the XML declaration (e.g., `<?xml version="1.0" encoding="UTF-8"?>`)
34
+ - methods:
35
+ - `read`: reads the XML file from the root element
36
+ - `write`: writes the XML to a file
37
+ - `find`: finds elements from the root element
38
+
39
+ ### ElementBase: (base class for Element, Comment, TextOnlyComment, CData, and Doctype)
40
+ - properties:
41
+ - `name`: the name of the element
42
+ - `parent`: the parent element
43
+ - methods:
44
+ - `find`: finds elements from the current element
45
+ - `remove`: removes the current element from its parent
46
+ - `comment_out`: comments out the current element
47
+ - `add_before`: adds an element before the current element
48
+ - `add_after`: adds an element after the current element
49
+ - `add_as_son_of`: adds an element as a son of the current element
50
+ - `set_as_parent_of`: sets the current element as the parent of another element
51
+ - `to_string`: converts the current element to a string
52
+
53
+
54
+ ### Usage Example
55
+
56
+ ```python
57
+ from pathlib import Path
58
+ from smartXML.xmltree import SmartXML, TextOnlyComment
59
+
60
+ input_file = Path('./example.xml')
61
+ xml = SmartXML(input_file)
62
+
63
+ firstName = xml.find('students|student|firstName', with_content='Bob')
64
+ bob = firstName.parent
65
+ bob.comment_out()
66
+ header = TextOnlyComment('Bob is out')
67
+ header.add_before(bob)
68
+
69
+ xml.write()
70
+ ```
71
+ result (example.xml):
72
+ ```xml
73
+ <students>
74
+ <!-- Bob is out -->
75
+ <!--
76
+ <student id="S002">
77
+ <firstName>Bob</firstName>
78
+ <lastName>Levi</lastName>
79
+ </student>
80
+ -->
81
+ </students>
82
+ ```
@@ -7,6 +7,8 @@ import pytest
7
7
  import random
8
8
 
9
9
 
10
+ test_file_name = "./files/test.tmp.xml"
11
+
10
12
  def _test_tree_integrity(xml_tree: SmartXML):
11
13
 
12
14
  def node_tree_integrity(xml: SmartXML, element: Element, name: str):
@@ -25,12 +27,11 @@ def _test_tree_integrity(xml_tree: SmartXML):
25
27
 
26
28
 
27
29
  def __create_file(content: str) -> Path:
28
- file_name = "./test.tmp.txt"
29
- f = open(file_name, "w")
30
+ f = open(test_file_name, "w")
30
31
  f.write(content)
31
32
  f.close()
32
33
 
33
- return Path(file_name)
34
+ return Path(test_file_name)
34
35
 
35
36
 
36
37
  @pytest.mark.all
@@ -988,7 +989,7 @@ def test_complex_comment_2():
988
989
 
989
990
  @pytest.mark.all
990
991
  def test_file_test_1():
991
- file_name = Path("./test_1.xml")
992
+ file_name = Path("./files/test_1.xml")
992
993
  xml = SmartXML(file_name)
993
994
  _test_tree_integrity(xml)
994
995
  tag = xml.find("lib:title")
@@ -998,10 +999,10 @@ def test_file_test_1():
998
999
 
999
1000
  @pytest.mark.all
1000
1001
  def test_file_test_2():
1001
- file_name = Path("./test_2.xml")
1002
+ file_name = Path("./files/test_2.xml")
1002
1003
  xml = SmartXML(file_name)
1003
1004
  _test_tree_integrity(xml)
1004
- xml.write(Path("./test.tmp.txt"))
1005
+ xml.write(Path(test_file_name))
1005
1006
  pass
1006
1007
 
1007
1008
 
@@ -1132,7 +1133,6 @@ def test_find_name_2():
1132
1133
 
1133
1134
 
1134
1135
  @pytest.mark.all
1135
- @pytest.mark.one
1136
1136
  def test_find_1():
1137
1137
  src = textwrap.dedent(
1138
1138
  """\
@@ -1427,7 +1427,7 @@ def test_bad_format_12():
1427
1427
  @pytest.mark.all
1428
1428
  def test_read_me_example():
1429
1429
  # README example test
1430
- input_file = Path('./readme_example.xml')
1430
+ input_file = Path('./files/readme_example.xml')
1431
1431
 
1432
1432
  xml = SmartXML(input_file)
1433
1433
  firstName = xml.find('students|student|firstName', with_content='Bob')
@@ -1436,7 +1436,7 @@ def test_read_me_example():
1436
1436
  header = TextOnlyComment('Bob is out')
1437
1437
  header.add_before(bob)
1438
1438
 
1439
- output_file = Path("./test.tmp.txt")
1439
+ output_file = Path(test_file_name)
1440
1440
  xml.write(output_file)
1441
1441
  result = output_file.read_text()
1442
1442
 
@@ -1523,6 +1523,7 @@ def test_find_all_with_content():
1523
1523
  </tag2>
1524
1524
  </tag2>
1525
1525
  <tag3/>
1526
+ <tag4>xxx</tag4>
1526
1527
  </head>
1527
1528
  """
1528
1529
  )
@@ -1535,9 +1536,19 @@ def test_find_all_with_content():
1535
1536
  for index in range(4):
1536
1537
  assert tags[index].attributes["id"] == str(index + 1)
1537
1538
 
1539
+ tag4 = xml.find(with_content="xxx")
1540
+ assert tag4
1541
+ assert tag4.name == "tag4"
1542
+
1543
+ tag4 = xml.find(with_content="xxx", only_one=False)
1544
+ assert len(tag4) == 1
1545
+ assert tag4[0].name == "tag4"
1546
+
1547
+
1548
+
1538
1549
  @pytest.mark.all
1539
1550
  def test_read_me_example_ver1():
1540
- input_file = Path('./readme_example.xml')
1551
+ input_file = Path('./files/readme_example.xml')
1541
1552
 
1542
1553
  xml = SmartXML(input_file)
1543
1554
  names = xml.find('students|student|firstName', only_one=False)
@@ -1548,7 +1559,7 @@ def test_read_me_example_ver1():
1548
1559
  header = TextOnlyComment('Bob is out')
1549
1560
  header.add_before(bob)
1550
1561
 
1551
- output_file = Path("./test.tmp.txt")
1562
+ output_file = Path(test_file_name)
1552
1563
  xml.write(output_file)
1553
1564
  result = output_file.read_text()
1554
1565
 
@@ -1622,7 +1633,7 @@ def test_build_tree():
1622
1633
 
1623
1634
  _test_tree_integrity(xml)
1624
1635
 
1625
- file_name = Path("./test.tmp.txt")
1636
+ file_name = Path(test_file_name)
1626
1637
  xml.write(file_name)
1627
1638
  result = file_name.read_text()
1628
1639
  assert result == dst
@@ -1964,4 +1975,72 @@ def test_c_data_3():
1964
1975
  assert result == src
1965
1976
 
1966
1977
 
1967
- # TODO add tests for read() and write and to_string()
1978
+ @pytest.mark.all
1979
+ def test_to_string():
1980
+ src = textwrap.dedent(
1981
+ """\
1982
+ <root>
1983
+ <tag1>
1984
+ <bbbbb/>
1985
+ <ccccc></ccccc>
1986
+ </tag1>
1987
+ </root>
1988
+ """
1989
+ )
1990
+
1991
+ dst1 = textwrap.dedent(
1992
+ """\
1993
+ <tag1>
1994
+ \t<bbbbb/>
1995
+ \t<ccccc></ccccc>
1996
+ </tag1>
1997
+ """
1998
+ )
1999
+
2000
+ file_name = __create_file(src)
2001
+ xml = SmartXML(file_name)
2002
+
2003
+ tag1 = xml.find("tag1")
2004
+
2005
+ tag1_str = tag1.to_string()
2006
+ assert tag1_str == dst1
2007
+
2008
+ @pytest.mark.all
2009
+ @pytest.mark.one
2010
+ def test_read():
2011
+
2012
+ xml = SmartXML()
2013
+
2014
+ with pytest.raises(ValueError) as error:
2015
+ xml.write()
2016
+ assert str(error.value) == "File name is not specified"
2017
+ assert error.type is ValueError
2018
+
2019
+ with pytest.raises(TypeError) as error:
2020
+ xml.read('ssss')
2021
+ assert str(error.value) == "file_name must be a pathlib.Path object"
2022
+ assert error.type is TypeError
2023
+
2024
+ with pytest.raises(FileNotFoundError) as error:
2025
+ xml.read(Path('ssss'))
2026
+ assert str(error.value) == "File ssss does not exist"
2027
+ assert error.type is FileNotFoundError
2028
+
2029
+
2030
+
2031
+ src = textwrap.dedent(
2032
+ """\
2033
+ <root>
2034
+ \t<AAA/>
2035
+ \t<![CDATA[A story about <coding> & "logic". The <tags> inside here are ignored by the parser.]]>
2036
+ \t<AAA/>
2037
+ </root>
2038
+ """
2039
+ )
2040
+
2041
+ file_name = __create_file(src)
2042
+ xml.read(file_name)
2043
+ xml.write()
2044
+ result = file_name.read_text()
2045
+ assert result == src
2046
+
smartxml-1.0.1/PKG-INFO DELETED
@@ -1,45 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: smartXML
3
- Version: 1.0.1
4
- Summary: smartXML package enables you to read, search, manipulate, and write XML files with ease
5
- Author-email: Dudu Arbel <duduarbel@gmail.com>
6
- License-Expression: MIT
7
- Keywords: python,example
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: Programming Language :: Python :: 3 :: Only
10
- Classifier: Programming Language :: Python :: 3.10
11
- Classifier: Programming Language :: Python :: 3.11
12
- Classifier: Programming Language :: Python :: 3.12
13
- Classifier: Operating System :: OS Independent
14
- Requires-Python: >=3.10
15
- Description-Content-Type: text/markdown
16
- Requires-Dist: requests>=2.31
17
- Provides-Extra: dev
18
- Requires-Dist: pytest>=8.0; extra == "dev"
19
- Requires-Dist: mypy>=1.8; extra == "dev"
20
- Requires-Dist: ruff>=0.3; extra == "dev"
21
-
22
- # smartXML
23
-
24
- The **smartXML** package enables you to read, search, manipulate, and write XML files with ease.
25
-
26
- The API is designed to be as simple as possible, but it will be enhanced according to usage and requests.
27
-
28
- ---
29
-
30
- ## Usage Example
31
-
32
- ```python
33
- from pathlib import Path
34
- from smartxml import SmartXML, TextOnlyComment
35
-
36
- input_file = Path('./example.xml')
37
- xml = SmartXML(input_file)
38
-
39
- firstName = xml.find('students|student|firstName', with_content='Bob')
40
- bob = firstName.parent
41
- bob.comment_out()
42
- header = TextOnlyComment('Bob is out')
43
- header.add_before(bob)
44
-
45
- xml.write()
smartxml-1.0.1/README.md DELETED
@@ -1,24 +0,0 @@
1
- # smartXML
2
-
3
- The **smartXML** package enables you to read, search, manipulate, and write XML files with ease.
4
-
5
- The API is designed to be as simple as possible, but it will be enhanced according to usage and requests.
6
-
7
- ---
8
-
9
- ## Usage Example
10
-
11
- ```python
12
- from pathlib import Path
13
- from smartxml import SmartXML, TextOnlyComment
14
-
15
- input_file = Path('./example.xml')
16
- xml = SmartXML(input_file)
17
-
18
- firstName = xml.find('students|student|firstName', with_content='Bob')
19
- bob = firstName.parent
20
- bob.comment_out()
21
- header = TextOnlyComment('Bob is out')
22
- header.add_before(bob)
23
-
24
- xml.write()
@@ -1,45 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: smartXML
3
- Version: 1.0.1
4
- Summary: smartXML package enables you to read, search, manipulate, and write XML files with ease
5
- Author-email: Dudu Arbel <duduarbel@gmail.com>
6
- License-Expression: MIT
7
- Keywords: python,example
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: Programming Language :: Python :: 3 :: Only
10
- Classifier: Programming Language :: Python :: 3.10
11
- Classifier: Programming Language :: Python :: 3.11
12
- Classifier: Programming Language :: Python :: 3.12
13
- Classifier: Operating System :: OS Independent
14
- Requires-Python: >=3.10
15
- Description-Content-Type: text/markdown
16
- Requires-Dist: requests>=2.31
17
- Provides-Extra: dev
18
- Requires-Dist: pytest>=8.0; extra == "dev"
19
- Requires-Dist: mypy>=1.8; extra == "dev"
20
- Requires-Dist: ruff>=0.3; extra == "dev"
21
-
22
- # smartXML
23
-
24
- The **smartXML** package enables you to read, search, manipulate, and write XML files with ease.
25
-
26
- The API is designed to be as simple as possible, but it will be enhanced according to usage and requests.
27
-
28
- ---
29
-
30
- ## Usage Example
31
-
32
- ```python
33
- from pathlib import Path
34
- from smartxml import SmartXML, TextOnlyComment
35
-
36
- input_file = Path('./example.xml')
37
- xml = SmartXML(input_file)
38
-
39
- firstName = xml.find('students|student|firstName', with_content='Bob')
40
- bob = firstName.parent
41
- bob.comment_out()
42
- header = TextOnlyComment('Bob is out')
43
- header.add_before(bob)
44
-
45
- xml.write()
File without changes