Skip to content

Commit

Permalink
Merge pull request #61 from xorrkaz/lxml-support
Browse files Browse the repository at this point in the history
Use lxml for XML extraction.
  • Loading branch information
einarnn authored Nov 15, 2024
2 parents 932f992 + 5938fc8 commit c4ba7f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
requests>=2.6
pyang>=2.5.0
lxml
18 changes: 13 additions & 5 deletions xym/xym.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os.path
import re
import sys
import xml.etree.ElementTree as ET
from lxml import etree as ET
from collections import Counter

import requests
Expand Down Expand Up @@ -699,7 +699,10 @@ def write_code_snippets_to_files(self):
code_snippet_file.write(line)

def extract_yang_model_xml(self, content):
root = ET.fromstring(content)
doc_parser = ET.XMLParser(
resolve_entities=False, recover=True, ns_clean=True, encoding="utf-8"
)
root = ET.fromstring(content.encode("utf-8"), doc_parser)
for sourcecode in root.iter("sourcecode"):
if not sourcecode.text:
continue
Expand Down Expand Up @@ -737,7 +740,8 @@ def extract_yang_model_xml(self, content):
match = self.MODULE_STATEMENT.match(line)
if match is None:
continue
lines = lines[i:]
mstart = i - 1
lines = lines[mstart:]
if not output_file:
self.warning('Missing file name in <sourcecode>')
if match.group(2) or match.group(5):
Expand Down Expand Up @@ -839,8 +843,12 @@ def xym(source_id, srcdir, dstdir, strict=False, strict_name=False, strict_examp
parser.add_argument("source",
help="The URL or file name of the RFC/draft text from "
"which to get the model")
parser.add_argument("--rfcxml", action='store_ture', default=False,
help="Parse a file in RFCXMLv3 format")
parser.add_argument(
"--rfcxml",
action="store_true",
default=False,
help="Parse a file in RFCXMLv3 format",
)
parser.add_argument("--srcdir", default='.',
help="Optional: directory where to find the source "
"text; default is './'")
Expand Down

0 comments on commit c4ba7f4

Please sign in to comment.