我正在尝试创建XML模式文件。我尝试进入,我已经找到了解决方案,我找到了这个(根据我的情况修改)
<xsd:element name="msgBLOB">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="mimeType" type="xsd:string" />
<xsd:attribute name="msgType" type="xsd:NMTOKEN" />
<xsd:attribute name="storeMethod" type="xsd:NMTOKEN" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="MsgOrValue">
<xsd:complexType>
<xsd:choice>
<xsd:element ref="msgBLOB" />
<xsd:element ref="metaDataValue" />
</xsd:choice>
</xsd:complexType>
</xsd:element>
<xsd:element name="MetaDataEntry">
<xsd:complexType>
<xsd:all>
<xsd:element ref="metaDataName"/>
<xsd:element ref="MsgOrValue" minOccurs="0" maxOccurs="1" />
<xsd:element ref="metaDataType" minOccurs="0" maxOccurs="1" />
<xsd:element ref="correlation" minOccurs="0" maxOccurs="1" />
</xsd:all>
</xsd:complexType>
</xsd:element>
但是,这不起作用。
我有错误消息
错误:元素'msgBLOB':不期望此元素。 错误:元素'msgBLOB':不期望此元素。 错误:元素'msgBLOB':不期望此元素。 错误:元素'msgBLOB':不期望此元素。 错误:元素'metaDataValue':不期望此元素。 错误:元素'metaDataValue':不期望此元素。 错误:元素'metaDataValue':不期望此元素。 错误:元素'metaDataValue':不期望此元素。 错误:元素'metaDataValue':不期望此元素。
完整的XML文件:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MonitoringEntries>
<MonitoringEntry><msgDateTimeStamp>2015-08-27T22:13:00</msgDateTimeStamp>
<direction>Received</direction>
<senderCode>JP GIS</senderCode>
<receiverCode>Panasonic Energy Europe</receiverCode>
<formatCode>EDIFACT</formatCode>
<typeCode>ORDERS</typeCode>
<subTypeCode>*</subTypeCode>
<communicationMethod>FILE</communicationMethod>
<statusID>Successful</statusID>
<acknowledged>N/A</acknowledged>
<division>6325cf87dd80f4b6a1c1e5b43b69bcc5c08cb501</division>
<documentID>0003587782</documentID>
<MetaDataEntries>
<MetaDataEntry>
<metaDataName>IDOC Message</metaDataName>
<msgBLOB mimeType='text/plain' msgType='base64' storeMethod='file'>ozeruoziruzo</msgBLOB>
</metaDataEntry>
<MetaDataEntry>
<metaDataName>Readable Version</metaDataName>
<msgBLOB mimeType='text/html' msgType='base64' storeMethod='file'>erzrz</msgBLOB>
</MetaDataEntry>
<MetaDataEntry>
<metaDataName>Filesize</metaDataName>
<metaDataType>Technical</metaDataType>
<correlation>No</correlation>
</MetaDataEntry>
</MetaDataEntries>
</MonitoringEntry>
</MonitoringEntries>
XSD:
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- Déclaration des éléments -->
<xsd:element name="msgDateTimeStamp" type="xsd:dateTime" />
<xsd:element name="direction" type="xsd:string" />
<xsd:element name="senderCode" type="xsd:string" />
<xsd:element name="receiverCode" type="xsd:string" />
<xsd:element name="formatCode" type="xsd:string" />
<xsd:element name="typeCode" type="xsd:string" />
<xsd:element name="subTypeCode" type="xsd:string" />
<xsd:element name="communicationMethod" type="xsd:string" />
<xsd:element name="statusID" type="xsd:string" />
<xsd:element name="acknowledged" type="xsd:string" />
<xsd:element name="division" type="xsd:string" />
<xsd:element name="documentID" type="xsd:string" />
<xsd:element name="metaDataName" type="xsd:string" />
<xsd:element name="metaDataType" type="xsd:string" />
<xsd:element name="metaDataValue" type="xsd:string" />
<xsd:element name="correlation" type="xsd:string" />
<xsd:element name="msgBLOB">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="mimeType" type="xsd:string" />
<xsd:attribute name="msgType" type="xsd:NMTOKEN" />
<xsd:attribute name="storeMethod" type="xsd:NMTOKEN" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="MsgOrValue">
<xsd:complexType>
<xsd:choice>
<xsd:element ref="msgBLOB" />
<xsd:element ref="metaDataValue" />
</xsd:choice>
</xsd:complexType>
</xsd:element>
<xsd:element name="MetaDataEntry">
<xsd:complexType>
<xsd:all>
<xsd:element ref="metaDataName" />
<xsd:element ref="MsgOrValue" minOccurs="0" maxOccurs="1" />
<xsd:element ref="metaDataType" minOccurs="0" maxOccurs="1" />
<xsd:element ref="correlation" minOccurs="0" maxOccurs="1" />
</xsd:all>
</xsd:complexType>
</xsd:element>
<xsd:element name="MetaDataEntries">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="MetaDataEntry" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="MonitoringEntry">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="msgDateTimeStamp" />
<xsd:element ref="direction" />
<xsd:element ref="senderCode" />
<xsd:element ref="receiverCode" />
<xsd:element ref="formatCode" />
<xsd:element ref="typeCode" />
<xsd:element ref="subTypeCode" />
<xsd:element ref="communicationMethod" />
<xsd:element ref="statusID" />
<xsd:element ref="acknowledged" />
<xsd:element ref="division" />
<xsd:element ref="documentID" />
<xsd:element ref="MetaDataEntries" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!-- Schéma XSD -->
<xsd:element name="MonitoringEntries">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="MonitoringEntry" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
答案 0 :(得分:0)
看起来XML文档缺少MetaDataEntry和msgBLOB之间的中间MsgOrValue元素。
如果您不想要这个中间级别,您可以使用替换组而不是选择,如下所示:
Option Explicit
Dim fs, logFile
Dim folder, subFolders, subFolder
Dim files, file
Set fs = CreateObject("Scripting.FileSystemObject")
'Log file name
Set logFile = fs.OpenTextFile("fileNameLogs.txt", 2, True)
'Directory you want listed
Set folder = fs.GetFolder("\\server\Data\Users")
'Write out sub folders
Set subFolders = folder.SubFolders
For Each subFolder In subFolders
logFile.Writeline(subFolder.Name)
Next
Set subFolders = Nothing
'Write out files
Set files = folder.files
For Each file In files
logFile.Writeline(file.Name)
Next
Set files = Nothing
logFile.Close
'Clean-up and reclaim memory
Set logFile = Nothing
Set folder = Nothing
Set fs = Nothing
以下是我成功验证XML文档的完整修改架构:
<xsd:element name="msgBLOB" substitutionGroup="MsgOrValue">
...
</xsd:element>
<xsd:element name="MsgOrValue" abstract="true"/>
答案 1 :(得分:0)
也许您不知道可以使用Visual Studio生成XSD架构(您没有提到您正在使用它,但它仍然可能有用)。
所以我已经下载了你的xml,在我的VS中打开并选择了XML - &gt;创建架构,如以下屏幕截图所示:
请注意第19行有一个拼写错误。
</metaDataEntry>
应以大写字母开头,并像</MetaDataEntry>
当我纠正它时,VS为我生成了这个XSD:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="MonitoringEntries">
<xs:complexType>
<xs:sequence>
<xs:element name="MonitoringEntry">
<xs:complexType>
<xs:sequence>
<xs:element name="msgDateTimeStamp" type="xs:dateTime" />
<xs:element name="direction" type="xs:string" />
<xs:element name="senderCode" type="xs:string" />
<xs:element name="receiverCode" type="xs:string" />
<xs:element name="formatCode" type="xs:string" />
<xs:element name="typeCode" type="xs:string" />
<xs:element name="subTypeCode" type="xs:string" />
<xs:element name="communicationMethod" type="xs:string" />
<xs:element name="statusID" type="xs:string" />
<xs:element name="acknowledged" type="xs:string" />
<xs:element name="division" type="xs:string" />
<xs:element name="documentID" type="xs:unsignedInt" />
<xs:element name="MetaDataEntries">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="MetaDataEntry">
<xs:complexType>
<xs:sequence>
<xs:element name="metaDataName" type="xs:string" />
<xs:element minOccurs="0" name="metaDataType" type="xs:string" />
<xs:element minOccurs="0" name="correlation" type="xs:string" />
<xs:element minOccurs="0" name="msgBLOB">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="mimeType" type="xs:string" use="required" />
<xs:attribute name="msgType" type="xs:string" use="required" />
<xs:attribute name="storeMethod" type="xs:string" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
如果这不是你要求的,你不能使用VS,请忽略。