File size: 1,658 Bytes
6fb15ba
41051ea
946e98d
6fb15ba
 
1bccc59
6fb15ba
1bccc59
 
946e98d
1bccc59
 
 
 
 
2fddd9e
6fb15ba
1bccc59
 
 
 
2fddd9e
1bccc59
 
 
6fb15ba
1bccc59
 
26e452e
1bccc59
 
6fb15ba
1bccc59
 
 
5ac6ff7
1bccc59
 
 
 
6fb15ba
1bccc59
2fddd9e
1bccc59
 
 
 
2fddd9e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import streamlit as st
import pandas as pd
import re
from io import BytesIO

st.set_page_config(page_title="XML to Excel Converter", layout="wide")

st.title("📄 XML to Excel Converter")
st.write("Extract **ErrorCode** and **Message** from XML text and export to Excel.")

# --- Text Area Container ---
xml_input = st.text_area(
    label="XML Data",
    height=300,
    placeholder="Paste your XML exception data here..."
)

# --- Button ---
if st.button("Generate Excel Data"):
    if not xml_input.strip():
        st.warning("⚠️ Please paste XML data before generating Excel.")
    else:
        # Regex to extract ErrorCode and Message values inside quotes
        pattern = r'ErrorCode="(.*?)".*?Message="(.*?)"'
        matches = re.findall(pattern, xml_input, re.DOTALL)

        if not matches:
            st.error("❌ No valid ErrorCode and Message found in the XML.")
        else:
            # Create DataFrame
            df = pd.DataFrame(matches, columns=["ErrorCode", "Message"])

            # Display extracted data
            st.success("✅ Data extracted successfully!")
            st.dataframe(df, use_container_width=True)

            # Convert to Excel
            output = BytesIO()
            with pd.ExcelWriter(output, engine="openpyxl") as writer:
                df.to_excel(writer, index=False, sheet_name="Errors")

            # Download Button
            st.download_button(
                label="⬇️ Download Excel",
                data=output.getvalue(),
                file_name="ErrorCodes.xlsx",
                mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            )