Skip to content

Commit

Permalink
Inital commit
Browse files Browse the repository at this point in the history
  • Loading branch information
metaodi committed Mar 14, 2024
0 parents commit c918dbc
Show file tree
Hide file tree
Showing 6 changed files with 376 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
env/
233 changes: 233 additions & 0 deletions content.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions fedlex.xml

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions index.html
@@ -0,0 +1,63 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quill Editor Demo</title>
<!-- Include Quill stylesheet -->
<link href="https://cdn.jsdelivr.net/npm/quill@2.0.0-rc.2/dist/quill.snow.css" rel="stylesheet" />

</head>
<body>

<!-- Create the editor container -->
<div id="editor">
<p>Hello World!</p>
<p>Some initial <strong>bold</strong> text</p>
<p><br /></p>
</div>

<!-- Include the Quill library -->
<script src="https://cdn.jsdelivr.net/npm/quill@2.0.0-rc.2/dist/quill.js"></script>

<!-- Initialize Quill editor -->
<script>
const quill = new Quill('#editor', {
theme: 'snow'
});
var jsonData = [
{ id: 1, text: 'Option 1' },
{ id: 2, text: 'Option 2' },
{ id: 3, text: 'Option 3' }
];

// Define custom select handler
Quill.register('modules/custom-select', function(quill, options) {
var container = document.createElement('select');
options.forEach(function(option) {
var optionElement = document.createElement('option');
optionElement.setAttribute('value', option.id);
optionElement.textContent = option.text;
container.appendChild(optionElement);
});
container.onchange = function() {
var value = container.value;
var selection = quill.getSelection();
quill.insertText(selection.index, container.options[container.selectedIndex].text);
};
this.container = container;
quill.container.parentNode.querySelector('.ql-custom-select').appendChild(container);
});

// Add custom select handler to Quill
document.querySelector('.ql-custom-select').addEventListener('change', function() {
var value = this.value;
var selection = quill.getSelection();
quill.insertText(selection.index, this.options[this.selectedIndex].text);
});
</script>


</body>
</html>

2 changes: 2 additions & 0 deletions requirements.txt
@@ -0,0 +1,2 @@
bluebell
muzzle
75 changes: 75 additions & 0 deletions xml_parse.py
@@ -0,0 +1,75 @@
import muzzle
import xml.etree.ElementTree as ET
import json

def extract_elements_with_attribute(root, attribute_name):
# Initialize list to store elements
elements_with_attribute = []

# Traverse XML and extract elements with the specified attribute
def traverse(element):
if attribute_name in element.attrib:
elements_with_attribute.append(element)
for child in element:
traverse(child)

traverse(root)

return elements_with_attribute

# Beispiel XML
xml_string = """
<root>
<element1 eID="1">
<subelement1>eID 1</subelement1>
</element1>
<element2>
<subelement2>eID 2</subelement2>
</element2>
<element3 eID="3">
<subelement3>eID 3</subelement3>
</element3>
</root>
"""

with open("fedlex.xml") as f:
xml_content = f.read().encode()


namespaces = {
"akn": "http://docs.oasis-open.org/legaldocml/ns/akn/3.0",
"xsd": "http://www.w3.org/2001/XMLSchema",
}
xmlparser = muzzle.XMLParser(namespaces)
xml = xmlparser.parse(xml_content)


uri_base = xmlparser.find(xml, './/akn:FRBRuri')
uri_value = uri_base.attrib['value']
print(f"URI: {uri_value}")

# Attribute Name
attribute_name = "eId"

# Extrahiere Elemente mit dem Attribut "eID"
elements = extract_elements_with_attribute(xml, attribute_name)


# Ausgabe der extrahierten Elemente
json_content = {}
for element in elements:
for par in xmlparser.findall(element, './akn:content/akn:p'):
content_id = f"{uri_value}/{element.attrib['eId']}"
print(f"{content_id}")
print(par.text)
print('')
json_content[content_id] = par.text

with open("content.json", "w") as fw:
fw.write(json.dumps(json_content, indent=4))





#print(xml.find('./FRBRuri'))

0 comments on commit c918dbc

Please sign in to comment.