gpt4 book ai didi

java - 如何让 DOM 可以读取 xml 文件?

转载 作者:行者123 更新时间:2023-11-30 08:14:05 25 4
gpt4 key购买 nike

我在尝试使用 DOM 解析 xml 文件时遇到问题。问题出在我处理的 xml 文件的结构中,因为它的标签之前有破折号,所以我要求如何删除 xml 文件中每个标签之前的所有破折号和空格。感谢帮助这是我处理的 xml 文件的示例:

  < ?xml version="1.0" encoding="ISO-8859-1" standalone="yes" ?> 

- < HWData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="hw_data.xsd">

< Header xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" AdaptationName="NWI3BulkUpload" AccessProtocol="NWI3" time="2013-05-29T13:39:34" uploaded="true" version="1.0" />

- < NE xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" vendorName="Nokia Siemens Networks" objectClass="NE" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031" NEId="PLMN-PLMN/RNC-6/WBTS-4031" NEType="WBTS" operationalState="enabled" locationName="GAB4031" nameFromPlanningSystem="" systemTitle="Nokia Flexi WCDMA Base Station">

- < EQHO vendorName="Nokia Siemens Networks" objectClass="EQHO" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-173" equipmentHolderId="173" equipmentHolderType="Subrack" equipmentHolderSpecificType="471469A-173" identificationCode="471469A" version="" serialNumber="L6103725271" userLabel="FSME" state="working">

< UNIT vendorName="N" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-173/UNIT-16" unitId="16" unitTypeActual="CORE_FSME" identificationCode="083833A" version="104" serialNumber="L6103725271" />

< UNIT vendorName="NOKIA SIEMENS NETWORKS" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-173/UNIT-225" unitId="225" unitTypeActual="FTLB" identificationCode="471984A" version="103" serialNumber="RY111112346" />
< /EQHO>
- < EQHO vendorName="NSN" objectClass="EQHO" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192" equipmentHolderId="40192" equipmentHolderType="Subrack" equipmentHolderSpecificType="472083A-40192" identificationCode="472083A" version="203" serialNumber="K9123521310" userLabel="FXDA" state="working">

< UNIT vendorName="AR" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192/UNIT-40266" unitId="40266" unitTypeActual="TILT" identificationCode="CV3PX310R-BTQ" version="" serialNumber="00000008496511644" />

< UNIT vendorName="AR" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192/UNIT-40267" unitId="40267" unitTypeActual="TILT" identificationCode="CV3PX310R-BTQ" version="" serialNumber="00000008496511642" />

< UNIT vendorName="AR" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192/UNIT-40268" unitId="40268" unitTypeActual="TILT" identificationCode="CV3PX310R-BTQ" version="" serialNumber="00000008496511641" />

< UNIT vendorName="AR" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192/UNIT-40269" unitId="40269" unitTypeActual="TILT" identificationCode="CV3PX310R-BTQ" version="" serialNumber="00000008496511643" />

< UNIT vendorName="AR" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192/UNIT-40282" unitId="40282" unitTypeActual="TILT" identificationCode="CV3PX310R-BTQ" version="" serialNumber="00000008496411404" />

< UNIT vendorName="AR" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192/UNIT-40284" unitId="40284" unitTypeActual="TILT" identificationCode="CV3PX310R-BTQ" version="" serialNumber="00000008496411401" />

< UNIT vendorName="AR" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192/UNIT-40298" unitId="40298" unitTypeActual="TILT" identificationCode="CV3PX310R-BTQ" version="" serialNumber="00000008496611944" />

< UNIT vendorName="AR" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192/UNIT-40300" unitId="40300" unitTypeActual="TILT" identificationCode="CV3PX310R-BTQ" version="" serialNumber="00000008496611941" />

< /EQHO>

- < EQHO vendorName="NSN" objectClass="EQHO" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192" equipmentHolderId="40192" equipmentHolderType="Subrack" equipmentHolderSpecificType="472083A-40192" identificationCode="472083A" version="203" serialNumber="K9123521310" userLabel="FXDA" state="working">

< UNIT vendorName="AR" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192/UNIT-40266" unitId="40266" unitTypeActual="TILT" identificationCode="CV3PX310R-BTQ" version="" serialNumber="00000008496511644" />

< UNIT vendorName="AR" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192/UNIT-40267" unitId="40267" unitTypeActual="TILT" identificationCode="CV3PX310R-BTQ" version="" serialNumber="00000008496511642" />

< UNIT vendorName="AR" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192/UNIT-40268" unitId="40268" unitTypeActual="TILT" identificationCode="CV3PX310R-BTQ" version="" serialNumber="00000008496511641" />

< UNIT vendorName="AR" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192/UNIT-40269" unitId="40269" unitTypeActual="TILT" identificationCode="CV3PX310R-BTQ" version="" serialNumber="00000008496511643" />
< UNIT vendorName="AR" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192/UNIT-40282" unitId="40282" unitTypeActual="TILT" identificationCode="CV3PX310R-BTQ" version="" serialNumber="00000008496411404" />

< UNIT vendorName="AR" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192/UNIT-40283" unitId="40283" unitTypeActual="TILT" identificationCode="CV3PX310R-BTQ" version="" serialNumber="00000008496411402" />

< UNIT vendorName="AR" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192/UNIT-40284" unitId="40284" unitTypeActual="TILT" identificationCode="CV3PX310R-BTQ" version="" serialNumber="00000008496411401" />

< UNIT vendorName="AR" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192/UNIT-40285" unitId="40285" unitTypeActual="TILT" identificationCode="CV3PX310R-BTQ" version="" serialNumber="00000008496411403" />

< UNIT vendorName="AR" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192/UNIT-40298" unitId="40298" unitTypeActual="TILT" identificationCode="CV3PX310R-BTQ" version="" serialNumber="00000008496611944" />

< UNIT vendorName="AR" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192/UNIT-40299" unitId="40299" unitTypeActual="TILT" identificationCode="CV3PX310R-BTQ" version="" serialNumber="00000008496611942" />

< UNIT vendorName="AR" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192/UNIT-40300" unitId="40300" unitTypeActual="TILT" identificationCode="CV3PX310R-BTQ" version="" serialNumber="00000008496611941" />

< UNIT vendorName="AR" objectClass="UNIT" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40192/UNIT-40301" unitId="40301" unitTypeActual="TILT" identificationCode="CV3PX310R-BTQ" version="" serialNumber="00000008496611943" />

< /EQHO>

< EQHO vendorName="Nokia Siemens Networks" objectClass="EQHO" objectClassVersion="1" MOID="NE-RNC-6/DN:NE-WBTS-4031/EQHO-40448" equipmentHolderId="40448" equipmentHolderType="Subrack" equipmentHolderSpecificType="472100A-40448" identificationCode="472100A" version="101" serialNumber="K9123314694" userLabel="FRGP" state="working" />

< /NE>

< /HWData>

最佳答案

在 notepad++ 中将当前目录中的所有 XML 文件的所有“- <”替换为“<”,或者通过 java 中的代码即可解决此问题。您可能还想将所有“<”替换为“<”,当您从中创建 DOM 时,它会正常编译。话虽如此,最好还是捕获问题的根源。

关于java - 如何让 DOM 可以读取 xml 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29902259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com