65 lines
2.5 KiB
Python
65 lines
2.5 KiB
Python
import json
|
|
from lxml import etree
|
|
|
|
# Cargar el JSON para obtener el UID de la instrucción Sr
|
|
json_file = r"C:\Trabajo\SIDEL\09 - SAE452 - Diet as Regular - San Giorgio in Bosco\ExportTia\CPU_315F-2_PN_DP\ProgramBlocks_XML\parsing\System_Run_Out.json"
|
|
xml_file = r"C:\Trabajo\SIDEL\09 - SAE452 - Diet as Regular - San Giorgio in Bosco\ExportTia\CPU_315F-2_PN_DP\ProgramBlocks_XML\System_Run_Out.xml"
|
|
|
|
with open(json_file, "r", encoding="utf-8") as f:
|
|
data = json.load(f)
|
|
|
|
# Encontrar la red 13 (ID: D5) y la instrucción Sr
|
|
sr_uid = None
|
|
for network in data["networks"]:
|
|
if network["id"] == "D5":
|
|
for instr in network["logic"]:
|
|
if instr["type"] == "Sr":
|
|
sr_uid = instr["uid"]
|
|
print(f"Instrucción Sr encontrada con UID: {sr_uid}")
|
|
break
|
|
break
|
|
|
|
if sr_uid:
|
|
print(f"\n=== BÚSQUEDA EN XML ORIGINAL ===")
|
|
# Buscar en el XML original la instrucción Sr con ese UID
|
|
tree = etree.parse(xml_file)
|
|
root = tree.getroot()
|
|
|
|
# Buscar la parte Sr con ese UId
|
|
sr_elements = root.xpath(f"//Part[@Name='Sr' and @UId='{sr_uid}']")
|
|
if sr_elements:
|
|
sr_element = sr_elements[0]
|
|
print(f"Elemento Sr encontrado en XML:")
|
|
print(
|
|
f"XML: {etree.tostring(sr_element, encoding='unicode', pretty_print=True)}"
|
|
)
|
|
else:
|
|
print(f"No se encontró Part con Name='Sr' y UId='{sr_uid}' en el XML")
|
|
|
|
# Buscar cualquier elemento con ese UID
|
|
any_elements = root.xpath(f"//*[@UId='{sr_uid}']")
|
|
if any_elements:
|
|
print(f"Elementos encontrados con UId='{sr_uid}':")
|
|
for elem in any_elements:
|
|
print(f" - Tag: {elem.tag}, Attributes: {elem.attrib}")
|
|
print(
|
|
f" XML: {etree.tostring(elem, encoding='unicode', pretty_print=True)[:200]}..."
|
|
)
|
|
else:
|
|
print(f"No se encontró NINGÚN elemento con UId='{sr_uid}' en el XML")
|
|
|
|
# También buscar wires que conecten a este UID
|
|
print(f"\n=== WIRES CONECTADOS AL SR UID {sr_uid} ===")
|
|
wire_elements = root.xpath(f"//Wire[*/@UId='{sr_uid}']")
|
|
if wire_elements:
|
|
print(f"Encontrados {len(wire_elements)} wires conectados:")
|
|
for i, wire in enumerate(wire_elements):
|
|
print(f"Wire {i+1}:")
|
|
print(
|
|
f" XML: {etree.tostring(wire, encoding='unicode', pretty_print=True)}"
|
|
)
|
|
else:
|
|
print("No se encontraron wires conectados al Sr")
|
|
else:
|
|
print("No se encontró instrucción Sr en la red 13")
|