我需要读取XML文档中的特定标记。我遇到的问题是并非每个XML都是相同的。如果XML包含多个图像,则需要每个循环a,但该标记名称为FilingConnectedDocument,而单个图像XML起始标记为FilingLeadDocument。我需要的XML信息是nc:DocumentReceivedDate,nc:DocumentDescriptionText和RegisterActionDescriptionText。任何指导都将不胜感激。
使用XML Reader的C#代码:
private void button1_Click(object sender, EventArgs e)
{
string sourceDir2 = @"server file path";
XmlReaderSettings settings2 = new XmlReaderSettings();
settings2.IgnoreComments = true;
settings2.IgnoreProcessingInstructions = true;
settings2.IgnoreWhitespace = true;
settings2.CheckCharacters = false;
// Reads only XML files from the specific folder
string[] fileEntries2 = Directory.GetFiles(sourceDir2, "*.xml");
foreach (string fileName in fileEntries2)
{
XmlReader xmlReader = XmlReader.Create(fileName, settings2);
while (xmlReader.Read())
{
}
}
}
XML格式:
<?xml version="1.0"?>
<RecordFilingRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:oasis:names:tc:legalxml-courtfiling:wsdl:WebServiceMessagingProfile-Definitions-4.0">
<RecordFilingRequestMessage xmlns:fsrsp="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:FilingStatusResponseMessage-4.0" xmlns:ecf="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:CommonTypes-4.0" xmlns:j="http://niem.gov/niem/domains/jxdm/4.0" xmlns:juvenile="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:JuvenileCase-4.0" xmlns:niem-xsd="http://niem.gov/niem/proxy/xsd/2.0" xmlns:domestic="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:DomesticCase-4.0" xmlns:s="http://niem.gov/niem/structures/2.0" xmlns:criminal="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:CriminalCase-4.0" xmlns:amcadext="http://www.amcad.com/NiemEcf/extensions/1.0" xmlns:i="http://niem.gov/niem/appinfo/2.0" xmlns:appellate="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:AppellateCase-4.0" xmlns:nc="http://niem.gov/niem/niem-core/2.0" xmlns:citation="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:CitationCase-4.0" xmlns:reviewcb="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:ReviewFilingCallbackMessage-4.0" xmlns:civil="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:CivilCase-4.0">
<nc:DocumentDescriptionText s:id="ReviewWorkQueueId">476</nc:DocumentDescriptionText>
<nc:DocumentDescriptionText s:id="ReviewWorkQueue">Circuit Criminal Existing Cases</nc:DocumentDescriptionText>
<nc:DocumentIdentification>
<nc:IdentificationID>6379325</nc:IdentificationID>
</nc:DocumentIdentification>
<nc:DocumentPostDate>
<nc:DateTime>2013-10-14T16:56:14.290623-04:00</nc:DateTime>
</nc:DocumentPostDate>
<nc:DocumentSubmitter>
<ecf:EntityPerson s:id="REVIEWER">
<nc:PersonName>
<nc:PersonGivenName></nc:PersonGivenName>
<nc:PersonSurName></nc:PersonSurName>
<nc:PersonFullName></nc:PersonFullName>
</nc:PersonName>
<nc:PersonOtherIdentification>
<nc:IdentificationID>27404</nc:IdentificationID>
<nc:IdentificationCategoryText>FLEPORTAL</nc:IdentificationCategoryText>
</nc:PersonOtherIdentification>
<nc:PersonOtherIdentification>
<nc:IdentificationID></nc:IdentificationID>
<nc:IdentificationCategoryText>FLEPORTAL_LOGONNAME</nc:IdentificationCategoryText>
</nc:PersonOtherIdentification>
<ecf:PersonAugmentation>
<nc:ContactInformation>
<nc:ContactEmailID></nc:ContactEmailID>
</nc:ContactInformation>
</ecf:PersonAugmentation>
</ecf:EntityPerson>
</nc:DocumentSubmitter>
<ecf:SendingMDELocationID>
<nc:IdentificationID>Filing Review MDE</nc:IdentificationID>
</ecf:SendingMDELocationID>
<ecf:SendingMDEProfileCode>urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:WebServicesMessaging-2.0</ecf:SendingMDEProfileCode>
<CoreFilingMessage xmlns="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:CoreFilingMessage-4.0">
<nc:DocumentEffectiveDate>
<nc:DateTime>2013-10-14T16:11:45.677-04:00</nc:DateTime>
</nc:DocumentEffectiveDate>
<nc:DocumentIdentification>
<nc:IdentificationID>6379325</nc:IdentificationID>
</nc:DocumentIdentification>
<nc:DocumentInformationCutOffDate>
<nc:DateTime>2013-10-14T16:11:45.677-04:00</nc:DateTime>
</nc:DocumentInformationCutOffDate>
<nc:DocumentPostDate>
<nc:DateTime>2013-10-14T16:11:45-04:00</nc:DateTime>
</nc:DocumentPostDate>
<nc:DocumentReceivedDate>
<nc:DateTime>2013-10-14T16:11:45.677-04:00</nc:DateTime>
</nc:DocumentReceivedDate>
<nc:DocumentSubmitter>
<ecf:EntityPerson s:id="FILER">
<nc:PersonName>
<nc:PersonGivenName></nc:PersonGivenName>
<nc:PersonSurName></nc:PersonSurName>
<nc:PersonNameSuffixText s:metadata="III">III</nc:PersonNameSuffixText>
<nc:PersonFullName></nc:PersonFullName>
</nc:PersonName>
<nc:PersonOtherIdentification>
<nc:IdentificationID>24759</nc:IdentificationID>
<nc:IdentificationCategoryText>FLEPORTAL</nc:IdentificationCategoryText>
</nc:PersonOtherIdentification>
<nc:PersonOtherIdentification>
<nc:IdentificationID>STB</nc:IdentificationID>
<nc:IdentificationCategoryText>FLEPORTAL_LOGONNAME</nc:IdentificationCategoryText>
</nc:PersonOtherIdentification>
<nc:PersonOtherIdentification>
<nc:IdentificationID>128820FL</nc:IdentificationID>
<nc:IdentificationCategoryText>BAR_NUMBER</nc:IdentificationCategoryText>
</nc:PersonOtherIdentification>
<nc:PersonOtherIdentification>
<nc:IdentificationID></nc:IdentificationID>
<nc:IdentificationCategoryText>EMPLOYER</nc:IdentificationCategoryText>
</nc:PersonOtherIdentification>
<ecf:PersonAugmentation>
<nc:ContactInformation>
<nc:ContactEmailID></nc:ContactEmailID>
<nc:ContactMailingAddress>
<nc:StructuredAddress>
<nc:AddressDeliveryPointText></nc:AddressDeliveryPointText>
<nc:LocationCityName></nc:LocationCityName>
<nc:LocationStateUSPostalServiceCode>FL</nc:LocationStateUSPostalServiceCode>
<nc:LocationStateName></nc:LocationStateName>
<nc:LocationPostalCode></nc:LocationPostalCode>
</nc:StructuredAddress>
<nc:AddressFullText></nc:AddressFullText>
</nc:ContactMailingAddress>
<nc:ContactTelephoneNumber s:id="PRIMARYPHONE">
<nc:FullTelephoneNumber>
<nc:TelephoneNumberFullID></nc:TelephoneNumberFullID>
</nc:FullTelephoneNumber>
</nc:ContactTelephoneNumber>
</nc:ContactInformation>
</ecf:PersonAugmentation>
</ecf:EntityPerson>
</nc:DocumentSubmitter>
<ecf:SendingMDELocationID s:id="Filing Assembly MDE">
<nc:IdentificationID>http://www.myflcourtaccess.com/Courts/UIPages/SimpleEFileFees.aspx?organizationId=5</nc:IdentificationID>
<nc:IdentificationID>209.16.117.2</nc:IdentificationID>
<nc:IdentificationCategoryText>FLEPORTAL</nc:IdentificationCategoryText>
</ecf:SendingMDELocationID>
<ecf:SendingMDEProfileCode>urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:WebServicesMessaging-2.0</ecf:SendingMDEProfileCode>
<ecf:ElectronicServiceInformation s:id="1">
<ecf:ServiceRecipientID s:id="24759" s:metadata="Samuel Bookhardt III">
<nc:IdentificationID>;</nc:IdentificationID>
<nc:IdentificationCategoryText>Electronic</nc:IdentificationCategoryText>
</ecf:ServiceRecipientID>
</ecf:ElectronicServiceInformation>
<ecf:ElectronicServiceInformation s:id="2">
<ecf:ServiceRecipientID s:id="-1" s:metadata="Phil Archer, State Attorney">
<nc:IdentificationID>;;</nc:IdentificationID>
<nc:IdentificationCategoryText>Electronic</nc:IdentificationCategoryText>
</ecf:ServiceRecipientID>
</ecf:ElectronicServiceInformation>
<criminal:Case>
<nc:ActivityDescriptionText s:id="Circuit Criminal">Other Crimes Against Persons</nc:ActivityDescriptionText>
<nc:ActivityStatus>
<nc:StatusText>ORIGINAL PEND </nc:StatusText>
<nc:StatusDate>
<nc:DateTime>2013-10-14T00:00:00-04:00</nc:DateTime>
</nc:StatusDate>
</nc:ActivityStatus>
<nc:CaseTitleText></nc:CaseTitleText>
<nc:CaseCategoryText s:id="40781916530">904</nc:CaseCategoryText>
<nc:CaseTrackingID></nc:CaseTrackingID>
<nc:CaseTrackingID s:id="ucn"></nc:CaseTrackingID>
<j:CaseAugmentation>
<j:CaseCourt>
<nc:OrganizationIdentification>
<nc:IdentificationID>5</nc:IdentificationID>
<nc:IdentificationCategoryText>FLEPORTAL_ORGANIZATION</nc:IdentificationCategoryText>
</nc:OrganizationIdentification>
<nc:OrganizationIdentification>
<nc:IdentificationID>2</nc:IdentificationID>
<nc:IdentificationCategoryText>FLEPORTAL_ORGANIZATION_UNIT</nc:IdentificationCategoryText>
</nc:OrganizationIdentification>
<nc:OrganizationIdentification>
<nc:IdentificationID>Trial</nc:IdentificationID>
<nc:IdentificationCategoryText>COURT_TYPE</nc:IdentificationCategoryText>
</nc:OrganizationIdentification>
<nc:OrganizationIdentification>
<nc:IdentificationID>Eighteenth Circuit</nc:IdentificationID>
<nc:IdentificationCategoryText>JUDICIAL_CIRCUIT_ID</nc:IdentificationCategoryText>
</nc:OrganizationIdentification>
<nc:OrganizationName></nc:OrganizationName>
<nc:OrganizationUnitName>Circuit </nc:OrganizationUnitName>
<j:CourtName></j:CourtName>
</j:CaseCourt>
</j:CaseAugmentation>
<ecf:CaseAugmentation>
<nc:LanguageCode xsi:nil="true" />
</ecf:CaseAugmentation>
</criminal:Case>
<FilingConfidentialityIndicator>false</FilingConfidentialityIndicator>
<FilingLeadDocument s:id="DOC00001" s:metadata="# Pages=3">
<nc:DocumentApplicationName>application/pdf</nc:DocumentApplicationName>
<nc:DocumentDescriptionText s:id="Motions">Motion to Set Bond</nc:DocumentDescriptionText>
<nc:DocumentFileControlID s:id="FileInputId">101</nc:DocumentFileControlID>
<nc:DocumentFileControlID s:id="Rule6PublicAnswer">-1</nc:DocumentFileControlID>
<nc:DocumentFileControlID s:id="Rule6ConfidentialAnswer">-1</nc:DocumentFileControlID>
<nc:DocumentFileControlID s:id="TypeOfConfidentialDocument">-1</nc:DocumentFileControlID>
<nc:DocumentPostDate>
<nc:DateTime>2013-10-14T16:11:45-04:00</nc:DateTime>
</nc:DocumentPostDate>
<nc:DocumentReceivedDate>
<nc:DateTime>2013-10-14T16:11:45.677-04:00</nc:DateTime>
</nc:DocumentReceivedDate>
<nc:DocumentSequenceID>1</nc:DocumentSequenceID>
<ecf:DocumentMetadata>
<j:RegisterActionDescriptionText s:id="2089067143">3022 </j:RegisterActionDescriptionText>
<ecf:FilingPartyID>
<nc:IdentificationID>24759</nc:IdentificationID>
<nc:IdentificationCategoryText>FLEPORTAL</nc:IdentificationCategoryText>
</ecf:FilingPartyID>
<ecf:SpecialHandlingInstructions />
</ecf:DocumentMetadata>
<ecf:DocumentRendition>
<ecf:DocumentRenditionMetadata>
<nc:DocumentApplicationName>application/pdf</nc:DocumentApplicationName>
<nc:DocumentFileControlID>bond jeremey carmichael.pdf</nc:DocumentFileControlID>
<ecf:DocumentAttachment s:id="ATT00001">
<nc:BinaryBase64Object></nc:BinaryBase64Object>
<nc:BinarySizeValue>12862</nc:BinarySizeValue>
<ecf:AttachmentSequenceID>1</ecf:AttachmentSequenceID>
</ecf:DocumentAttachment>
</ecf:DocumentRenditionMetadata>
</ecf:DocumentRendition>
</FilingLeadDocument>
<FilingConnectedDocument s:id="DOC00002" s:metadata="# Pages=1">
<nc:DocumentApplicationName>application/pdf</nc:DocumentApplicationName>
<nc:DocumentDescriptionText s:id="Notices">Notice of Hearing</nc:DocumentDescriptionText>
<nc:DocumentFileControlID s:id="FileInputId">102</nc:DocumentFileControlID>
<nc:DocumentFileControlID s:id="Rule6PublicAnswer">-1</nc:DocumentFileControlID>
<nc:DocumentFileControlID s:id="Rule6ConfidentialAnswer">-1</nc:DocumentFileControlID>
<nc:DocumentFileControlID s:id="TypeOfConfidentialDocument">-1</nc:DocumentFileControlID>
<nc:DocumentPostDate>
<nc:DateTime>2013-10-14T16:11:45-04:00</nc:DateTime>
</nc:DocumentPostDate>
<nc:DocumentReceivedDate>
<nc:DateTime>2013-10-14T16:11:45.677-04:00</nc:DateTime>
</nc:DocumentReceivedDate>
<nc:DocumentSequenceID>2</nc:DocumentSequenceID>
<ecf:DocumentMetadata>
<j:RegisterActionDescriptionText s:id="2089067191">6724 </j:RegisterActionDescriptionText>
<ecf:FilingPartyID>
<nc:IdentificationID>24759</nc:IdentificationID>
<nc:IdentificationCategoryText>FLEPORTAL</nc:IdentificationCategoryText>
</ecf:FilingPartyID>
</ecf:DocumentMetadata>
<ecf:DocumentRendition>
<ecf:DocumentRenditionMetadata>
<nc:DocumentApplicationName>application/pdf</nc:DocumentApplicationName>
<nc:DocumentFileControlID>NOH Bond Nebbia 10.11.13.pdf</nc:DocumentFileControlID>
<ecf:DocumentAttachment s:id="ATT00002">
<nc:BinaryBase64Object></nc:BinaryBase64Object>
<nc:BinarySizeValue>8812</nc:BinarySizeValue>
<ecf:AttachmentSequenceID>2</ecf:AttachmentSequenceID>
</ecf:DocumentAttachment>
</ecf:DocumentRenditionMetadata>
</ecf:DocumentRendition>
</FilingConnectedDocument>
</CoreFilingMessage>
<RecordDocketingMessage xmlns="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:RecordDocketingMessage-4.0">
<nc:DocumentIdentification>
<nc:IdentificationID>6379325</nc:IdentificationID>
</nc:DocumentIdentification>
<nc:DocumentPostDate>
<nc:DateTime>2013-10-14T16:56:14.290623-04:00</nc:DateTime>
</nc:DocumentPostDate>
<nc:DocumentSubmitter>
<ecf:EntityPerson s:id="REVIEWER">
<nc:PersonName>
<nc:PersonGivenName></nc:PersonGivenName>
<nc:PersonSurName></nc:PersonSurName>
<nc:PersonFullName></nc:PersonFullName>
</nc:PersonName>
<nc:PersonOtherIdentification>
<nc:IdentificationID>27404</nc:IdentificationID>
<nc:IdentificationCategoryText>FLEPORTAL</nc:IdentificationCategoryText>
</nc:PersonOtherIdentification>
<nc:PersonOtherIdentification>
<nc:IdentificationID></nc:IdentificationID>
<nc:IdentificationCategoryText>FLEPORTAL_LOGONNAME</nc:IdentificationCategoryText>
</nc:PersonOtherIdentification>
<ecf:PersonAugmentation>
<nc:ContactInformation>
<nc:ContactEmailID></nc:ContactEmailID>
</nc:ContactInformation>
</ecf:PersonAugmentation>
</ecf:EntityPerson>
</nc:DocumentSubmitter>
<ecf:SendingMDELocationID>
<nc:IdentificationID>Filing Review MDE</nc:IdentificationID>
</ecf:SendingMDELocationID>
<ecf:SendingMDEProfileCode>urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:WebServicesMessaging-2.0</ecf:SendingMDEProfileCode>
<j:CaseCourt>
<nc:OrganizationIdentification>
<nc:IdentificationID>5</nc:IdentificationID>
<nc:IdentificationCategoryText>FLEPORTAL_ORGANIZATION</nc:IdentificationCategoryText>
</nc:OrganizationIdentification>
<nc:OrganizationIdentification>
<nc:IdentificationID>2</nc:IdentificationID>
<nc:IdentificationCategoryText>FLEPORTAL_ORGANIZATION_UNIT</nc:IdentificationCategoryText>
</nc:OrganizationIdentification>
<nc:OrganizationIdentification>
<nc:IdentificationID>Trial</nc:IdentificationID>
<nc:IdentificationCategoryText>COURT_TYPE</nc:IdentificationCategoryText>
</nc:OrganizationIdentification>
<nc:OrganizationIdentification>
<nc:IdentificationID>Eighteenth Circuit</nc:IdentificationID>
<nc:IdentificationCategoryText>JUDICIAL_CIRCUIT_ID</nc:IdentificationCategoryText>
</nc:OrganizationIdentification>
<nc:OrganizationName>Brevard</nc:OrganizationName>
<nc:OrganizationUnitName>Circuit Criminal</nc:OrganizationUnitName>
<j:CourtName>Brevard Circuit Criminal</j:CourtName>
</j:CaseCourt>
<nc:CaseTrackingID>052013CF050219AXXXXX</nc:CaseTrackingID>
<ecf:ReviewedLeadDocument s:id="REVIEWEDDOC00001">
<nc:DocumentFiledDate>
<nc:DateTime>2013-10-14T00:00:00</nc:DateTime>
</nc:DocumentFiledDate>
<nc:DocumentPostDate>
<nc:DateTime>2013-10-14T16:11:45</nc:DateTime>
</nc:DocumentPostDate>
<nc:DocumentReceivedDate>
<nc:DateTime>2013-10-14T16:11:45.677</nc:DateTime>
</nc:DocumentReceivedDate>
<nc:DocumentSequenceID>1</nc:DocumentSequenceID>
<nc:DocumentStatus>
<nc:StatusText>ACCEPTED</nc:StatusText>
</nc:DocumentStatus>
<ecf:DocumentMetadata>
<j:RegisterActionDescriptionText s:id="2089067143">3022 </j:RegisterActionDescriptionText>
<ecf:ParentDocumentReference s:ref="DOC00001" />
</ecf:DocumentMetadata>
<ecf:DocumentRendition>
<ecf:DocumentRenditionMetadata s:metadata="3" />
</ecf:DocumentRendition>
</ecf:ReviewedLeadDocument>
<ecf:ReviewedConnectedDocument s:id="REVIEWEDDOC00002">
<nc:DocumentFiledDate>
<nc:DateTime>2013-10-14T00:00:00</nc:DateTime>
</nc:DocumentFiledDate>
<nc:DocumentPostDate>
<nc:DateTime>2013-10-14T16:11:45</nc:DateTime>
</nc:DocumentPostDate>
<nc:DocumentReceivedDate>
<nc:DateTime>2013-10-14T16:11:45.677</nc:DateTime>
</nc:DocumentReceivedDate>
<nc:DocumentSequenceID>2</nc:DocumentSequenceID>
<nc:DocumentStatus>
<nc:StatusText>ACCEPTED</nc:StatusText>
</nc:DocumentStatus>
<ecf:DocumentMetadata>
<j:RegisterActionDescriptionText s:id="2089067191">6724 </j:RegisterActionDescriptionText>
<ecf:ParentDocumentReference s:ref="DOC00002" />
</ecf:DocumentMetadata>
<ecf:DocumentRendition>
<ecf:DocumentRenditionMetadata s:metadata="1" />
</ecf:DocumentRendition>
</ecf:ReviewedConnectedDocument>
</RecordDocketingMessage>
<payment:PaymentMessage xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-1.0" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-1.0" xmlns:receipt="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:PaymentReceiptMessage-4.0" xmlns:payment="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:PaymentMessage-4.0">
<payment:PayerName></payment:PayerName>
<cac:AllowanceCharge>
<cac:ID identificationSchemeID="NA" identificationSchemeName="Filing fee" identificationSchemeAgencyID="-1">NA</cac:ID>
<cbc:ChargeIndicator>true</cbc:ChargeIndicator>
<cbc:PrepaidIndicator>false</cbc:PrepaidIndicator>
<cbc:SequenceNumeric>1</cbc:SequenceNumeric>
<cbc:Amount amountCurrencyID="USD">0</cbc:Amount>
<cac:Reason>Filing fee</cac:Reason>
</cac:AllowanceCharge>
<cac:AllowanceCharge>
<cac:ID identificationSchemeID="NA" identificationSchemeName="Motions Motion to Set Bond" identificationSchemeAgencyID="101">NA</cac:ID>
<cbc:ChargeIndicator>true</cbc:ChargeIndicator>
<cbc:PrepaidIndicator>false</cbc:PrepaidIndicator>
<cbc:SequenceNumeric>2</cbc:SequenceNumeric>
<cbc:Amount amountCurrencyID="USD">0</cbc:Amount>
<cac:Reason>Motions Motion to Set Bond</cac:Reason>
</cac:AllowanceCharge>
<cac:AllowanceCharge>
<cac:ID identificationSchemeID="NA" identificationSchemeName="Notices Notice of Hearing" identificationSchemeAgencyID="102">NA</cac:ID>
<cbc:ChargeIndicator>true</cbc:ChargeIndicator>
<cbc:PrepaidIndicator>false</cbc:PrepaidIndicator>
<cbc:SequenceNumeric>3</cbc:SequenceNumeric>
<cbc:Amount amountCurrencyID="USD">0</cbc:Amount>
<cac:Reason>Notices Notice of Hearing</cac:Reason>
</cac:AllowanceCharge>
<cac:Address>
<cac:AddressLine>
<cbc:Line>1980 Michigan Ave.</cbc:Line>
<cbc:Line />
<cbc:Line>Cocoa</cbc:Line>
<cbc:Line>FL</cbc:Line>
<cbc:Line>32922</cbc:Line>
</cac:AddressLine>
</cac:Address>
</payment:PaymentMessage>
</RecordFilingRequestMessage>
</RecordFilingRequest>
答案 0 :(得分:2)
这样做,
string xmlFile = File.ReadAllText(@"Yourxml.xml");
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(xmlFile);
XmlNodeList nodeList = xmldoc.GetElementsByTagName("FilingLeadDocument");
List<info> inforamtion = new List<info>();
foreach (XmlElement node in nodeList)
{
info inf=new info();
inf.RegisterActionDescriptionText = node.GetElementsByTagName("j:RegisterActionDescriptionText")[0].InnerText;
inf.DocumentDescriptionText = node.GetElementsByTagName("nc:DocumentDescriptionText")[0].InnerText;
inf.DocumentReceivedDate = Convert.ToDateTime(node.GetElementsByTagName("nc:DocumentReceivedDate")[0].FirstChild.InnerText);
inforamtion.Add(inf);
}
class info
{
internal string RegisterActionDescriptionText { get; set; }
internal string DocumentDescriptionText { get; set; }
internal DateTime DocumentReceivedDate { get; set; }
}
答案 1 :(得分:1)
使用LINQ to XML可以减少痛苦。这种情况下的技巧是处理文档中定义的所有命名空间。但是使用 XNamespace.Get 方法和 XName 连接运算符重载并不太难。
private static IEnumerable<Tuple<DateTime, string, string>> GetDocumentsData(string folderPath)
{
var filingMessageNamespace = XNamespace.Get("urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:CoreFilingMessage-4.0");
var ncNamespace = XNamespace.Get("http://niem.gov/niem/niem-core/2.0");
var ecfNamespace = XNamespace.Get("urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:CommonTypes-4.0");
var jNamespace = XNamespace.Get("http://niem.gov/niem/domains/jxdm/4.0");
return Directory
.GetFiles(folderPath, "XML*.xml")
.Select(XDocument.Load)
.SelectMany(
file =>
file.Descendants(filingMessageNamespace + "FilingLeadDocument")
.Concat(file.Descendants(filingMessageNamespace + "FilingConnectedDocument")))
.Select(
documentNode =>
Tuple.Create(
DateTime.Parse(documentNode.Element(ncNamespace + "DocumentReceivedDate").Element(ncNamespace + "DateTime").Value),
documentNode.Element(ncNamespace + "DocumentDescriptionText").Value.Trim(),
documentNode.Element(ecfNamespace + "DocumentMetadata").Element(jNamespace + "RegisterActionDescriptionText").Value.Trim()))
.ToArray();
}
如果您想了解更多信息,可以启动here。请记住,整个API比 XmlDocument的 DOM方法更直观,并且透明地使用LINQ到对象。