LuaXml ライブラリを使ってみました。ただし、これは特定の属性の最初のサブテーブルのみを返し、それ以上には進まないため、その機能は制限されています。次に、文字列パターンの一致を試みましたが、行き止まりになり、タスクを完全に達成できませんでした。LuaExpat ライブラリは lua の lib フォルダーにあり、lom.lua というファイルもあります。しかし、多くの場合、機能しないか、「モジュールが見つかりません」というエラーが表示されます
私のXMLファイルは次のようになります:
<Service>
<NewInstance ref="5A">
<Std>DiscoveredElement</Std>
<Key>5A</Key>
<Attributes>
<Attribute name="TARGET_TYPE" value="weblogic_cluster" />
<Attribute name="DISCOVERED_NAME" value="/Farm_soa4_sys20_soa4_domain/soa4_domain/WSM4_Cluster" />
<Attribute name="BROKEN_REASON" value="0" />
<Attribute name="TARGET_NAME" value="/Farm_soa4_sys20_soa4_domain/soa4_domain/WSM4_Cluster" />
<Attribute name="EMD_URL" value="https://uxsys460.schneider.com:3872/emd/main/" />
</Attributes>
</NewInstance>
<NewInstance ref="6C">
<Std>DiscoveredElement</Std>
<Key>6C</Key>
<Attributes>
<Attribute name="TARGET_TYPE" value="oracle_weblogic_nodemanager" />
<Attribute name="SERVICE_TYPE" value=" " />
<Attribute name="ORG_ID" value="0" />
<Attribute name="TARGET_NAME" value="Oracle WebLogic NodeManager-uxlab090" />
</Attributes>
</NewInstance>
<NewInstance ref="98">
<Std>DiscoveredElement</Std>
<Key>98</Key>
<Attributes>
<Attribute name="TARGET_TYPE" value="composite" />
<Attribute name="SERVICE_TYPE" value=" " />
<Attribute name="TARGET_NAME" value="SYS-IMG-Grp" />
<Attribute name="EMD_URL" value="" />
</Attributes>
</NewInstance>
<NewRelationship>
<Parent>
<Instance ref="98" />
</Parent>
<GenericRelations>
<Relations type="contains">
<Instance ref="5A" />
</Relations>
</GenericRelations>
</NewRelationship>
<NewRelationship>
<Parent>
<Instance ref="5A" />
</Parent>
<GenericRelations>
<Relations type="contains">
<Instance ref="6C" />
</Relations>
</GenericRelations>
</NewRelationship>
<NewRelationship>
<Parent>
<Instance ref="5A" />
</Parent>
<GenericRelations>
<Relations type="contains">
<Instance ref="98" />
</Relations>
</GenericRelations>
</NewRelationship>
</Service>
私のアジェンダは、NewInstance ID とそれに対応するターゲット タイプとターゲット名、およびその関係タイプと関連するインスタンス ref の ID を、そのターゲット タイプとターゲット名とともに表示することです。
NewInstance ID - 5A
Target Type - weblogic_cluster
Target Name - /Farm_soa4_sys20_soa4_domain/soa4_domain/WSM4_Cluster
Relation Type - contains
Instance ref - 6C
Target Type - oracle_weblogic_nodemanager
Target Name - Oracle WebLogic NodeManager-uxlab090
Instance ref - 98
Target Type - composite
Target Name - SYS-IMG-Grp
現在、LuaXml を使用してこれを実現することはできません。以下にリストする文字列パターン マッチングのコードは、リレーション タイプまでのタスクを達成するのに役立ちますが、正確ではありません
コードは次のとおりです。
a={}
b={}
c={}
d={}
p=0
i=0
q=0
local file = io.open("oem_topology_output.xml", "rb") -- Open file for reading (binary data)
for instance in file:read("*a"):gmatch("<NewInstance ref=\"(.-)\">") do
a[i] = instance
i = i+1
end
file:close()
local files = io.open("oem_topology_output.xml", "rb") -- Open file for reading (binary data)
for instances in files:read("*a"):gmatch("<NewInstance ref=\".-\">(.-)</NewInstance>") do
TARGET_TYPE = instances:match('TARGET_TYPE.-value="(.-)"')
TARGET_NAME = instances:match('TARGET_NAME.-value="(.-)"')
b[p] = TARGET_TYPE
c[p] = TARGET_NAME
p =p+1
end
local file = io.open("oem_topology_output.xml", "rb") -- Open file for reading (binary data)
for type in file:read("*a"):gmatch("<Relations type=\"(.-)\">") do
d[q] = type
q = q+1
end
files:close()
for j=0,i-1 do
print("INSTANCE ID : ", a[j])
print("TARGET TYPE : ", b[j])
print("TARGET NAME : ", c[j])
print("RELATION TYPE : ",d[j])
end
必要な方法で XMl ファイルを解析できるようにするために、どのアプローチに従うべきかを提案してください。どの組み込みライブラリが適切な機能を提供するか。あなたが提案した場合、LuaExpat は、それがうまくいかない理由を教えてくれます。