我正在尝试使用我没有源代码的应用程序。我正在尝试在XML文件中连接一些数据。我相信我的文件正确匹配应用程序所需的模式,但我得到的文件中的每个元素都有“无法找到元素的架构信息”的消息。我已经将应用程序代码解压缩并在visual studio中重建了,我自己也得到了错误。
我要继续前进,只是转储代码......它很长,但我开始认为这是一个非常糟糕的骨头错误。
要导入的XML:
<WorkOrders>
<WorkOrder>
<Action>SAVE</Action>
<UserDef1>NotRequired1</UserDef1>
<UserDef2>NotRequired2</UserDef2>
<UserDef3>NotRequired3</UserDef3>
<UserDef4>NotRequired4</UserDef4>
<UserDef5>NotRequired5</UserDef5>
<UserDef6>NotRequired6</UserDef6>
<UserDef7>-1</UserDef7>
<UserDef8>-2</UserDef8>
<AutoRelease>N</AutoRelease> <!--Probably can hardcode as N-->
<BuildInstructions>Not Required BuildInstructions</BuildInstructions>
<!--<BuildLocation>Not required BuildLocation</BuildLocation>-->
<Company></Company> <!--should match compan on the item master-->
<!--<DimensionUm></DimensionUm>-->
<DueDate>12-31-2011</DueDate>
<!--<Error></Error>-->
<FinishedItem>SERIAL_TEST</FinishedItem>
<QtyToBeBuilt>12345</QtyToBeBuilt>
<!--<QtyUm></QtyUm>
<RevisionNum></RevisionNum>-->
<Warehouse>PPLant</Warehouse>
<WeightUm></WeightUm>
<WOAllocMethod></WOAllocMethod>
<WorkOrderDetails>
<Action>SAVE</Action>
<UserDef1>NotRequired1</UserDef1>
<UserDef2>NotRequired2</UserDef2>
<UserDef3>NotRequired3</UserDef3>
<UserDef4>NotRequired4</UserDef4>
<UserDef5>NotRequired5</UserDef5>
<UserDef6>NotRequired6</UserDef6>
<UserDef7>-1</UserDef7>
<UserDef8>-2</UserDef8>
<AllocationRule>WorkOrderAllocation</AllocationRule>
<BuildLevel>1</BuildLevel>
<!--<BuildSequence>1</BuildSequence>-->
<Company></Company>
<ComponentItem>SERIAL_TEST</ComponentItem>
<FromLocation></FromLocation>-->
<!-- these fields allow users to increase/decrease the component quantity required
<IncQtyAmount></IncQtyAmount>
<IncQtyEligible></IncQtyEligible>
<IncQtyMinAmount></IncQtyMinAmount>
<IncQtyType></IncQtyType>-->
<!-- <LogisticsUnit></LogisticsUnit>
<Lot></Lot>
<ParentLogisticsUnit></ParentLogisticsUnit>-->
<QtyNeededPerItem>10</QtyNeededPerItem>
<!--<QuantityUm></QuantityUm>-->
<Warehouse>PPLant</Warehouse>
</WorkOrderDetails>
<WorkOrderId>ExampleWorkOrderID001</WorkOrderId>
<AllocationRule>WorkOrderAllocation</AllocationRule>
</WorkOrder>
</WorkOrders>
架构:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="WorkOrderDownload" targetNamespace="http://www.asdf.com/asdfNET/Interface" elementFormDefault="qualified" xmlns="http://www.asdf.com/asdfNET/Interface" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2008">
<xs:include schemaLocation="InterfaceEntity.xsd" />
<xs:element name="WorkOrders" nillable="false" type="WorkOrderList" />
<xs:complexType name="WorkOrderList">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" name="WorkOrder" nillable="true" type="WorkOrder" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="WorkOrder">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="AutoRelease" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="BuildInstructions" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="BuildLocation" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="Company" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="DimensionUm" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="DueDate" type="xs:dateTime" />
<xs:element minOccurs="0" maxOccurs="1" name="Error" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="FinishedItem" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="InterfaceEntity" type="InterfaceEntity" />
<xs:element minOccurs="0" maxOccurs="1" name="InternalWorkOrderNum" type="xs:int" />
<xs:element minOccurs="0" maxOccurs="1" name="ItemClass" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="ItemColor" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="ItemCost">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="0" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="ItemDescription" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="ItemHeight">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="0" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="ItemLength">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="0" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="ItemSize" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="ItemStyle" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="ItemValue">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="0" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="ItemWeight">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="0" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="ItemWidth">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="0" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="PlannedUnitBuildTime">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="0" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="QtyToBeBuilt">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="1" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="QtyUm" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="RevisionNum">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="1" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="VolumeUm" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="Warehouse" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="WeightUm" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="WOAllocMethod" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="WorkOrderDetails" type="WorkOrderDetailList" />
<xs:element minOccurs="0" maxOccurs="1" name="WorkOrderId" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="WorkOrderDetailList">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="WorkOrderDetail" nillable="true" type="WorkOrderDetail" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="WorkOrderDetail">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="AllocationRule" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="BuildLevel">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="1" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="BuildSequence">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="1" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="Company" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="ComponentItem" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="FromLocation" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="IncQtyAmount" type="xs:double" />
<xs:element minOccurs="0" maxOccurs="1" name="IncQtyEligible" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="IncQtyMinAmount">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="0" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="IncQtyType" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="InterfaceEntity" type="InterfaceEntity" />
<xs:element minOccurs="0" maxOccurs="1" name="InternalWorkOrderNum">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="0" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="LogisticsUnit" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="Lot" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="ParentLogisticsUnit" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="QtyNeededPerItem">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="1" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="QuantityUm" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="Warehouse" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;
namespace WorkOrderInterfaceValidation
{
class Program
{
static void Main(string[] args)
{
helper h = new helper();
h.main();
}
}
class helper
{
StringBuilder _valErrorMsgs;
public helper()
{
_valErrorMsgs = new StringBuilder();
}
public void main()
{
try
{
string error = "No error";
Console.WriteLine("hello world");
ValidateSchemaWithURI("C:\\Program Files\\software\\asdf\\2010\\Interface\\Input\\ExampleWorkOrder001.xml",
"http://www.asdf.com/asdfNET/Interface",
"\\\\localhost\\asdf\\Schemas\\Interface\\WorkOrderDownload.xsd",
out error
);
error += " err";
Console.WriteLine(error);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.ReadKey();
}
public XmlReader ValidateSchemaWithURI(string inputUri, string targetNamespace, string schemaPath, out string error)
{
//StringBuilder _valErrorMsgs = new StringBuilder();
XmlReader reader = null;
XmlReader reader2;
try
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.Schemas.Add(targetNamespace, schemaPath);
settings.IgnoreWhitespace = true;
settings.ValidationType = ValidationType.Schema;
settings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings;
settings.ValidationEventHandler += new ValidationEventHandler(this.SchemaValidationEventHandler);
reader = XmlReader.Create(inputUri, settings);
foreach (var v in settings.Schemas.Schemas())
{
foreach (var e in ((XmlSchema)v).Attributes)
{
e.ToString();
}
}
while (reader.Read())
{
}
reader2 = reader;
}
catch (XmlException exception)
{
_valErrorMsgs.Append(exception.Message).Append(";");
Console.WriteLine(exception.Message);
reader2 = null;
}
finally
{
error = _valErrorMsgs.ToString();
if (reader != null)
{
reader.Close();
}
}
return reader2;
}
private void SchemaValidationEventHandler(object sender, ValidationEventArgs args)
{
this._valErrorMsgs.Append(args.Exception.Message).Append(";");
}
}
}
错误消息:
XmlException:找不到元素'WorkOrders'的架构信息。;找不到元素'WorkOrder'的架构信息。;找不到元素'Action'的架构信息。;找不到架构信息元素'UserDef1'.;找不到元素'UserDef2'的架构信息。;找不到元素'UserDef3'的架构信息。;找不到元素'UserDef4'的架构信息。;找不到架构....的信息。
答案 0 :(得分:4)
我认为你错过了命名空间。尝试:
<WorkOrders xmlns="http://www.manh.com/ILSNET/Interface">