如何使用XSD和MVC从数据集生成XML文件

时间:2015-08-27 17:38:26

标签: c# xml xsd

我有一个引用其他XSD文件的XSD文件。 tomcat应用程序使用它来生成带有水样结果的XML文件。 在MVC应用程序中,我需要查询数据库,获取行,然后将它们转换为通过引用XSD文件格式化的XML文档。我能解决的唯一解决方案就是拥有一个现有的XML文件并将标记和加载到字符串中并循环遍历字符串,用行的值替换标记。

.NET MVC5中有什么东西可以做这样的事吗?我很难过。 以下是一些相关内容。

==========================================

顶部的XML文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<EN:eDWR xmlns:EN="urn:us:net:exchangenetwork"
    xmlns:SDWIS="http://www.epa.gov/sdwis"
    xmlns:ns3="http://www.epa.gov/xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <EN:Submission EN:submissionFileCreatedDate="2012-07-21"
        EN:submissionFileName="B_14271BJB.csv" EN:submissionID="1">
        <EN:LabReport>
            <EN:LabIdentification>
                <EN:LabAccreditation>
                    <EN:LabAccreditationIdentifier>OR100024</EN:LabAccreditationIdentifier>
                    <EN:LabAccreditationAuthorityName>STATE</EN:LabAccreditationAuthorityName>
                </EN:LabAccreditation>
            </EN:LabIdentification>
            <EN:Sample>
                <SDWIS:RecordID>155628</SDWIS:RecordID>
                <EN:SampleIdentification>
                    <EN:LabSampleIdentifier>123321</EN:LabSampleIdentifier>
                    <EN:PWSIdentifier>OR4100237</EN:PWSIdentifier>
                    <EN:PWSFacilityIdentifier>DIST-A</EN:PWSFacilityIdentifier>
                    <EN:SampleRuleCode>TC</EN:SampleRuleCode>
                    <EN:SampleMonitoringTypeCode>RP</EN:SampleMonitoringTypeCode>

===================================

xsd文件完成。它引用同一文件夹中的其他xsd文件:

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSPY v5 rel. 4 U (http://www.xmlspy.com) by Leslie Flagler (SAIC) -->
<xsd:schema targetNamespace="urn:us:net:exchangenetwork" xmlns:SDWIS="http://www.epa.gov/sdwis" xmlns:EN="urn:us:net:exchangenetwork" xmlns:facid="http://www.epa.gov/xml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="qualified" version="3.0">
    <xsd:annotation>
        <xsd:documentation/>
    </xsd:annotation>
    <xsd:include schemaLocation="./EDWR_MetaData.xsd"/>
    <xsd:include schemaLocation="./EDWR_ContactPoint.xsd"/>
    <xsd:include schemaLocation="./SDWIS_LabReport.xsd"/>
    <xsd:include schemaLocation="./EDWR_Authentication.xsd"/>
    <xsd:element name="eDWR">
        <xsd:annotation>
            <xsd:documentation>This is the standard regulatory schema
                approved by the USEPA and multi-state Lab to State
                Drinking Water Integrated Project Team</xsd:documentation>
        </xsd:annotation>
        <xsd:complexType>
            <xsd:annotation>
                <xsd:documentation>This is enfoTech EDWR schema</xsd:documentation>
            </xsd:annotation>
            <xsd:sequence>
                <xsd:element ref="EN:MetaData" minOccurs="0"/>
                <xsd:element ref="EN:Receiver" minOccurs="0"/>
                <xsd:element ref="EN:Sender" minOccurs="0"/>
                <xsd:element ref="EN:Submission"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
    <xsd:complexType name="SubmissionDataType">
        <xsd:annotation>
            <xsd:documentation>Transction information</xsd:documentation>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element ref="EN:LabReport" minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element ref="EN:SubmissionCertification" minOccurs="0"/>
        </xsd:sequence>
        <xsd:attribute name="submissionID" type="xsd:string"/>
        <xsd:attribute name="submissionFileName" type="xsd:string"/>
        <xsd:attribute name="submissionFileCreatedDate" type="xsd:date"/>
    </xsd:complexType>
    <xsd:element name="MetaData" type="EN:MetaDataDataType">
        <xsd:annotation>
            <xsd:documentation>General information about the schema</xsd:documentation>
        </xsd:annotation>
    </xsd:element>
    <xsd:element name="Receiver" type="EN:ContactPointDataType">
        <xsd:annotation>
            <xsd:documentation>Regulatory agency and contact to receive
                the e-DWR submission file</xsd:documentation>
        </xsd:annotation>
    </xsd:element>
    <xsd:element name="Sender" type="EN:ContactPointDataType">
        <xsd:annotation>
            <xsd:documentation>The sender of the e-DWR submission file</xsd:documentation>
        </xsd:annotation>
    </xsd:element>
    <xsd:element name="LabReport" type="EN:LabReportDataType">
        <xsd:annotation>
            <xsd:documentation>Lab Analysis Report (includes Lead and
                Copper Report, Water Quality Parameters, and
                Bacteriological Analysis Report, etc)</xsd:documentation>
            <xsd:documentation>Chemical Analysis Report (includes Lead
                and Copper Report, Water Quality Parameters, and
                Bacteriological Analysis Report)</xsd:documentation>
        </xsd:annotation>
    </xsd:element>
    <xsd:element name="SubmissionCertification" type="EN:AuthenticationDataType">
        <xsd:annotation>
            <xsd:documentation>Submission Certification</xsd:documentation>
        </xsd:annotation>
    </xsd:element>
    <xsd:element name="Submission" type="EN:SubmissionDataType">
        <xsd:annotation>
            <xsd:documentation>Information pertaining to a drinking
                water report submission</xsd:documentation>
        </xsd:annotation>
    </xsd:element>
</xsd:schema>

0 个答案:

没有答案