我想要验证xml子节点,就像我想检查节点<PNAME>
值是否正在使用<I>
,然后<PTYP>
和<PGROUP>
值应该以字母&#开头34; I&#34;否则脚本应显示错误。
这是我的xml文件。
<PARAMETER>
<ETPAR_GUIX>
<item>
<PNAME>COAS_1</PNAME>
<PTYP>X</PTYP>
<PDESC>Generated Table for View</PDESC>
<PINDEX>0001</PINDEX>
<PGROUP>GETTAB</PGROUP>
<XMLREF_TYP>T</XMLREF_TYP>
<PSTRUC_TYP>T</PSTRUC_TYP>
<PREF_TYPE>VIEW</PREF_TYPE>
<PREF_NAME>COAS</PREF_NAME>
<PDATLEN>0000</PDATLEN>
<PINTLEN>000000</PINTLEN>
<PDECIMALS>000000</PDECIMALS>
<SORT_LNR>0001</SORT_LNR>
<PREF_NAME2>COAS</PREF_NAME2>
<VAL_TYPE>T</VAL_TYPE>
<TAB_INDEX>0</TAB_INDEX>
<DEEP_STRU>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xml.sap.com/2003/05/eCATT/ddic" version="1.0">
<xsd:complexType name="COAS">
<annotation>
<documentation>I==O==C=S=K==D=COAS=A==L=000000=doc=Generated Table for View</documentation>
</annotation>
<sequence>
<element name="MANDT" minOccurs="0">
<annotation>
<documentation>I==O==C==K=X=D=MANDT=A=C=L=000003=doc=Client</documentation>
</annotation>
<simpleType>
<restriction base="string">
<maxLength value="3"/>
</restriction>
</simpleType>
</element>
<element name="AUFNR" minOccurs="0">
<annotation>
<documentation>I==O==C==K=X=D=AUFNR=A=C=L=000012=doc=Order Number</documentation>
</annotation>
<simpleType>
<restriction base="string">
<maxLength value="12"/>
</restriction>
</simpleType>
</element>
</DEEP_STRU>
</item>
<item>
<PNAME>I_ORDER_NUMBER_FROM_TABLE</PNAME>
<PTYP>I</PTYP>
<PDESC>Generated Table for View</PDESC>
<PINDEX>0001</PINDEX>
<PGROUP>I.01</PGROUP>
<XMLREF_TYP>T</XMLREF_TYP>
<PSTRUC_TYP>T</PSTRUC_TYP>
<PREF_TYPE>VIEW</PREF_TYPE>
<PREF_NAME>COAS</PREF_NAME>
<PDATLEN>0000</PDATLEN>
<PINTLEN>000000</PINTLEN>
<PDECIMALS>000000</PDECIMALS>
<SORT_LNR>0001</SORT_LNR>
<PREF_NAME2>COAS</PREF_NAME2>
<VAL_TYPE>T</VAL_TYPE>
<TAB_INDEX>0</TAB_INDEX>
<DEEP_STRU>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xml.sap.com/2003/05/eCATT/ddic" version="1.0">
<xsd:complexType name="COAS">
<annotation>
<documentation>I==O==C=S=K==D=COAS=A==L=000000=doc=Generated Table for View</documentation>
</annotation>
<sequence>
<element name="MANDT" minOccurs="0">
<annotation>
<documentation>I==O==C==K=X=D=MANDT=A=C=L=000003=doc=Client</documentation>
</annotation>
<simpleType>
<restriction base="string">
<maxLength value="3"/>
</restriction>
</simpleType>
</element>
<element name="AUFNR" minOccurs="0">
<annotation>
<documentation>I==O==C==K=X=D=AUFNR=A=C=L=000012=doc=Order Number</documentation>
</annotation>
<simpleType>
<restriction base="string">
<maxLength value="12"/>
</restriction>
</simpleType>
</element>
</DEEP_STRU>
</item>
</ETPAR_GUIX>
</PARAMETER>
请在vbscript中提供具有相同上述条件的解决方案,以验证用&#34; V&#34;和&#34; E&#34;也。以下vbscript代码仅适用于包含3或4个项目节点的xml,但My xml包含50个项目节点。所以我找不到解决方案所以请帮助我
我的Vbscript
XMLDataFile = "D:\Automation\newparamters.xml"
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = False
xmlDoc.Load(XMLDataFile)
xmlDoc.validateOnParse = True
If xmlDoc.Load(XMLDataFile) Then
MsgBox "SUCCESS loading XML File"
Else
MsgBox "ERROR loading XML File"
End If
counter=0
Set root = xmlDoc.documentElement
Set items = root.childNodes
for each item in items
myPNAME = xmlDoc.getElementsByTagName("PNAME").item(counter).text
myPTYP = xmlDoc.getElementsByTagName("PTYP").item(counter).text
myPGROUP = xmlDoc.getElementsByTagName("PGROUP").item(counter).text
If (Left(myPNAME, 1) = "I") Then
msgbox("myPNAME Starts with I")
IsValid = True
If (Left(myPTYP, 1) <> "I") Then
IsValid = False
End If
If (Left(myPGROUP, 1) <> "I" )Then
IsValid = False
End If
If IsValid = False Then
msgbox(myPNAME & " is not valid.")
End If
IsValid = True
End If
counter=counter+1
next
在上面的代码中,如果我写了Set items = root.childNodes,那么在xml文件中,根节点应为1但我有另一个根节点,如<ETPAR_GUIX>
,并且在此根节点中包含所有子节点,如<item>
所以请为如何检查或验证子节点的子节点提供解决方案。