[英]Access XML Nodes in c#
I'm trying to access nc:StructuredAddress where the preceding ecf:CaseParticipantRole = 'Debtor '. 我正在尝试访问nc:StructuredAddress,其中前面的ecf:CaseParticipantRole ='Debtor'。 Not sure if there's always a trailing space or not since this is example XML so I need to accommodate for trailing whitespace. 由于这是示例XML,因此不确定是否始终存在尾随空格,因此我需要容纳尾随空格。 Subsequently, I'd also like to access the associated nc:LocationCityName, nc:LocationStateUsPostalServiceCode and nc:LocationPostalCode for that ecf:CaseParticipantRole. 随后,我还要访问该ecf:CaseParticipantRole的关联的nc:LocationCityName,nc:LocationStateUsPostalServiceCode和nc:LocationPostalCode。
I've tried using SelectNodes and using GetElementsByTagName with variations of starts-with(text()='Debtor ']". I'm not sure if I can even add more node names after the text() clause. Regardless... No luck with either. Any suggestions? I have very little exposure to XML so be gentle if I'm doing something idiotic. 我试过使用SelectNodes和GetElementsByTagName一起使用starts-with(text()='Debtor']“的变体。我不确定是否可以在text()子句之后添加更多节点名称。无论如何...两者都不好运,有什么建议吗?我很少接触XML,所以如果我做一些愚蠢的事情,请保持谦虚。
Here's the XML. 这是XML。
<ebn:EBNBatch xmlns="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:CoreFilingMessage-4.0"
xmlns:ebn="http://ebn.uscourts.gov/EBN-BankruptcyCase-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ebn.uscourts.gov/EBN-BankruptcyCase-1.0 http://ebn.uscourts.gov/xsd/EBN-BankruptcyCase-1.0.xsd"
xmlns:ecf="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:CommonTypes-4.0"
xmlns:bankruptcy="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:BankruptcyCase-4.0"
xmlns:j="http://niem.gov/niem/domains/jxdm/4.0"
xmlns:nc="http://niem.gov/niem/niem-core/2.0" xmlns:s="http://niem.gov/niem/structures/2.0" >
<nc:DocumentIdentification>
<nc:IdentificationID>21-573-104452-1 </nc:IdentificationID>
</nc:DocumentIdentification>
<nc:DocumentPostDate>
<nc:DateTime>2014-07-21T16:27:17 </nc:DateTime>
</nc:DocumentPostDate>
<ecf:SendingMDELocationID>
<nc:IdentificationID>BNC </nc:IdentificationID>
</ecf:SendingMDELocationID>
<ecf:SendingMDEProfileCode>PDF_Embedded_XML</ecf:SendingMDEProfileCode>
<ebn:BankruptcyCase>
<ebn:BankruptcyFilingDate>
<nc:Date>2014-07-21T00:00:00 </nc:Date>
</ebn:BankruptcyFilingDate>
<nc:CaseTitleText>Olive Oil</nc:CaseTitleText>
<nc:CaseCategoryText>BK</nc:CaseCategoryText>
<nc:CaseDocketID>99-12345</nc:CaseDocketID>
<j:CaseAugmentation>
<j:CaseCourt>
<nc:OrganizationIdentification>
<nc:IdentificationID>0970-2 </nc:IdentificationID>
</nc:OrganizationIdentification>
<nc:OrganizationLocation>
<nc:LocationAddress>
<nc:StructuredAddress>
<nc:LocationStreet>
<nc:StreetFullText>230 N 1ST AVE </nc:StreetFullText>
<nc:StreetFullText>STE 101 </nc:StreetFullText>
</nc:LocationStreet>
<nc:LocationCityName>PHOENIX </nc:LocationCityName>
<nc:LocationStateUSPostalServiceCode>AZ </nc:LocationStateUSPostalServiceCode>
<nc:LocationPostalCode>85003-0608 </nc:LocationPostalCode>
</nc:StructuredAddress>
</nc:LocationAddress>
</nc:OrganizationLocation>
<nc:OrganizationName>United States Bankruptcy Court </nc:OrganizationName>
<nc:OrganizationName>District of Arizona </nc:OrganizationName>
<nc:OrganizationPrimaryContactInformation>
<nc:ContactTelephoneNumber>
<nc:FullTelephoneNumber>
<nc:TelephoneNumberFullID>6026824000 </nc:TelephoneNumberFullID>
</nc:FullTelephoneNumber>
</nc:ContactTelephoneNumber>
</nc:OrganizationPrimaryContactInformation>
<j:CourtName>District of Arizona </j:CourtName>
</j:CaseCourt>
<j:CaseInitiatingParty>
<nc:EntityPersonReference s:ref="Debtor"/>
</j:CaseInitiatingParty>
<j:CaseJudge>
<nc:RoleOfPersonReference s:ref="Judge"/>
</j:CaseJudge>
<j:CaseOtherEntity>
<nc:EntityPersonReference s:ref="Joint_Debtor"/>
</j:CaseOtherEntity>
<j:CaseOtherEntity>
<nc:EntityPersonReference s:ref="Notice_Recipient"/>
</j:CaseOtherEntity>
<j:CaseInitiatingAttorney>
<nc:RoleOfPersonReference s:ref="Attorney"/>
</j:CaseInitiatingAttorney>
</j:CaseAugmentation>
<ecf:CaseAugmentation>
<ecf:CaseParticipant>
<nc:EntityPerson s:id="Debtor">
<nc:PersonName>
<nc:PersonFullName>Olive Oil </nc:PersonFullName>
</nc:PersonName>
</nc:EntityPerson>
<ecf:CaseParticipantRoleCode>Debtor </ecf:CaseParticipantRoleCode>
<nc:ContactInformation>
<nc:ContactMailingAddress>
<nc:StructuredAddress>
<nc:LocationStreet>
<nc:StreetFullText>
123 Deserted Rd.
Black Canyon City, Arizona 85324
</nc:StreetFullText>
</nc:LocationStreet>
<nc:LocationCityName>BLACK CANYON CITY </nc:LocationCityName>
<nc:LocationStateUSPostalServiceCode>AZ </nc:LocationStateUSPostalServiceCode>
<nc:LocationPostalCode>85324 </nc:LocationPostalCode>
</nc:StructuredAddress>
</nc:ContactMailingAddress>
</nc:ContactInformation>
</ecf:CaseParticipant>
<ecf:CaseParticipant>
<nc:EntityPerson s:id="Joint_Debtor">
<nc:PersonName>
<nc:PersonFullName>Herman Munster </nc:PersonFullName>
</nc:PersonName>
</nc:EntityPerson>
<ecf:CaseParticipantRoleCode>Joint_Debtor </ecf:CaseParticipantRoleCode>
<nc:ContactInformation>
<nc:ContactMailingAddress>
<nc:StructuredAddress>
<nc:LocationStreet>
<nc:StreetFullText>
123 Deserted Rd.
Black Canyon City, Arizona 85324
</nc:StreetFullText>
</nc:LocationStreet>
<nc:LocationCityName>BLACK CANYON CITY </nc:LocationCityName>
<nc:LocationStateUSPostalServiceCode>AZ </nc:LocationStateUSPostalServiceCode>
<nc:LocationPostalCode>85324 </nc:LocationPostalCode>
</nc:StructuredAddress>
</nc:ContactMailingAddress>
</nc:ContactInformation>
</ecf:CaseParticipant>
<ecf:CaseParticipant>
<ecf:EntityOrganization s:id="Notice_Recipient">
<nc:OrganizationName>
MR. TXT11N
</nc:OrganizationName>
</ecf:EntityOrganization>
<ecf:CaseParticipantRoleCode>Notice_Recipient </ecf:CaseParticipantRoleCode>
<nc:ContactInformation>
<nc:ContactMailingAddress>
<nc:StructuredAddress>
<nc:LocationStreet>
<nc:StreetFullText>
2525 NETWORK PL
</nc:StreetFullText>
</nc:LocationStreet>
<nc:LocationCityName>HERNDON </nc:LocationCityName>
<nc:LocationStateUSPostalServiceCode>VA </nc:LocationStateUSPostalServiceCode>
<nc:LocationPostalCode>20171-3514 </nc:LocationPostalCode>
</nc:StructuredAddress>
</nc:ContactMailingAddress>
</nc:ContactInformation>
</ecf:CaseParticipant>
<ecf:CaseParticipant>
<ecf:EntityPerson s:id="Judge">
<nc:PersonOtherIdentification>
<nc:IdentificationID>RJH </nc:IdentificationID>
<nc:IdentificationCategoryText>Initials </nc:IdentificationCategoryText>
</nc:PersonOtherIdentification>
</ecf:EntityPerson>
<ecf:CaseParticipantRoleCode>Judge </ecf:CaseParticipantRoleCode>
</ecf:CaseParticipant>
<ecf:CaseParticipant>
<nc:EntityPerson s:id="Attorney">
<nc:PersonName>
<nc:PersonFullName>Mickey Mouse </nc:PersonFullName>
</nc:PersonName>
</nc:EntityPerson>
<ecf:CaseParticipantRoleCode>Attorney </ecf:CaseParticipantRoleCode>
<nc:ContactInformation>
<nc:ContactMailingAddress>
<nc:StructuredAddress>
<nc:LocationStreet>
<nc:StreetFullText>
6738 E CAVE CREEK RD
</nc:StreetFullText>
</nc:LocationStreet>
<nc:LocationCityName>CAVE CREEK </nc:LocationCityName>
<nc:LocationStateUSPostalServiceCode>AZ </nc:LocationStateUSPostalServiceCode>
<nc:LocationPostalCode>85331-8640 </nc:LocationPostalCode>
</nc:StructuredAddress>
</nc:ContactMailingAddress>
</nc:ContactInformation>
</ecf:CaseParticipant>
</ecf:CaseAugmentation>
<bankruptcy:AssetNoticeIndicator>false</bankruptcy:AssetNoticeIndicator>
<bankruptcy:NumberOfCreditorsValueLevelCode/>
<bankruptcy:EstimatedAssetsValueLevelCode/>
<bankruptcy:EstimatedDebtsValueLevelCode/>
<bankruptcy:SmallBusinessIndicator>false</bankruptcy:SmallBusinessIndicator>
<bankruptcy:Section1121eIndicator>false</bankruptcy:Section1121eIndicator>
<bankruptcy:DebtorTypeCode/>
<bankruptcy:JointPetitionIndicator>true</bankruptcy:JointPetitionIndicator>
<bankruptcy:NatureOfDebtCode/>
<bankruptcy:VoluntaryIndicator>false</bankruptcy:VoluntaryIndicator>
<bankruptcy:BankruptcyStatute>
<j:StatuteCodeIdentification>
<nc:IdentificationID>7 </nc:IdentificationID>
</j:StatuteCodeIdentification>
</bankruptcy:BankruptcyStatute>
<bankruptcy:Debtor/>
<ebn:DebtorInfo>
<nc:EntityPersonReference s:ref="Debtor"/>
</ebn:DebtorInfo>
<ebn:DebtorInfo>
<nc:EntityPersonReference s:ref="Joint_Debtor"/>
</ebn:DebtorInfo>
<ebn:BankruptcyFormCodeText></ebn:BankruptcyFormCodeText>
<ebn:BankruptcyFormCategory>Notice</ebn:BankruptcyFormCategory>
<ebn:BankruptcyFormNameText>pdf</ebn:BankruptcyFormNameText>
<ebn:BankruptcyNoticeShortNameText>Order</ebn:BankruptcyNoticeShortNameText>
<ebn:NoticePageCount>2</ebn:NoticePageCount>
</ebn:BankruptcyCase>
<FilingConfidentialityIndicator>false</FilingConfidentialityIndicator>
<FilingLeadDocument s:id="_notice">
<nc:DocumentApplicationName>Ghostscript</nc:DocumentApplicationName>
<nc:DocumentDescriptionText>Bankruptcy Notice</nc:DocumentDescriptionText>
<nc:DocumentLanguageCode>eng</nc:DocumentLanguageCode>
<ecf:DocumentMetadata>
<j:RegisterActionDescriptionText/>
<ecf:FilingAttorneyID/>
<ecf:FilingPartyID/>
</ecf:DocumentMetadata>
<ecf:DocumentRendition>
<ecf:DocumentRenditionMetadata>
<ecf:DocumentAttachment s:id="_.pdf">
<nc:BinaryDescriptionText>application/gs </nc:BinaryDescriptionText>
<nc:BinaryLocationURI/>
</ecf:DocumentAttachment>
</ecf:DocumentRenditionMetadata>
</ecf:DocumentRendition>
</FilingLeadDocument>
And here's the C# code I have, tweaking the Name1 and Address sections in an attempt to get "something" to work. 这是我拥有的C#代码,对Name1和Address部分进行了调整,以尝试使“某些东西”正常工作。
XmlDocument xmlNotice = new XmlDocument();
XmlNamespaceManager xmlNameSpc = new XmlNamespaceManager(xmlNotice.NameTable);
xmlNameSpc.AddNamespace("nc", "http://niem.gov/niem/niem-core/2.0");
xmlNameSpc.AddNamespace("ecf", "urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:CommonTypes-4.0");
XDocument xmlNot = XDocument.Parse(xml);
XmlNodeList xmlNodes;
xmlNotice.LoadXml(xml);
// DocumentId
string strDocumentId = string.Empty;
xmlNodes = xmlNotice.GetElementsByTagName("nc:DocumentIdentification");
for (int i = 0; i <= xmlNodes.Count - 1; i++)
{
strDocumentId = xmlNodes[i].ChildNodes.Item(0).InnerText.Trim();
System.Diagnostics.Debug.WriteLine("Doc Id: " + strDocumentId);
}
// Name1
string strName1 = string.Empty, strName2 = string.Empty, strDebtorAddress = string.Empty;
xmlNodes = xmlNotice.GetElementsByTagName("nc:EntityPerson");
for (int i = 0; i <= xmlNodes.Count - 1; i++)
{
if (xmlNodes[i].Attributes != null)
{
if (xmlNodes[i].Attributes["s:id"].Value.Equals("Debtor"))
{
strName1 = xmlNodes[i].ChildNodes.Item(0).InnerText.Trim();
XmlNodeList xnl = xmlNodes[i].SelectNodes("//ContactInformation/ContactMailingAddress/StructuredAddress/LocationStreet/StreetFullText");
//strDebtorAddress = xmlNodes[i].SelectNodes("//ContactInformation/ContactMailingAddress/StructuredAddress/LocationStreet/StreetFullText").InnerText.Trim();
}
else if (xmlNodes[i].Attributes["s:id"].Value.Equals("Joint_Debtor"))
strName2 = xmlNodes[i].ChildNodes.Item(0).InnerText.Trim();
}
}
System.Diagnostics.Debug.WriteLine("Debtor: " + strName1 + " and Joint_Debtor: " + strName2);
System.Diagnostics.Debug.WriteLine("Debtor Address: " + strDebtorAddress);
// Chapter
string strChapter = string.Empty;
xmlNodes = xmlNotice.GetElementsByTagName("bankruptcy:BankruptcyStatute");
for (int i = 0; i <= xmlNodes.Count - 1; i++)
{
strChapter = xmlNodes[i].ChildNodes.Item(0).InnerText.Trim();
System.Diagnostics.Debug.WriteLine("Chapter: " + strChapter);
}
// Case Number
string strCaseNumber = string.Empty;
xmlNodes = xmlNotice.GetElementsByTagName("nc:CaseDocketID");
for (int i = 0; i <= xmlNodes.Count - 1; i++)
{
strCaseNumber = xmlNodes[i].ChildNodes.Item(0).InnerText.Trim();
System.Diagnostics.Debug.WriteLine("Case #: " + strCaseNumber);
}
// Date Filed
string strDateFiled = string.Empty;
xmlNodes = xmlNotice.GetElementsByTagName("ebn:BankruptcyFilingDate");
for (int i = 0; i <= xmlNodes.Count - 1; i++)
{
strDateFiled = xmlNodes[i].ChildNodes.Item(0).InnerText.Trim();
System.Diagnostics.Debug.WriteLine("Date Filed; " + strDateFiled);
}
// Received Date
string strDateReceived = string.Empty;
xmlNodes = xmlNotice.GetElementsByTagName("nc:DocumentPostDate");
for (int i = 0; i <= xmlNodes.Count - 1; i++)
{
strDateReceived = xmlNodes[i].ChildNodes.Item(0).InnerText.Trim();
System.Diagnostics.Debug.WriteLine("Date Received: " + strDateReceived);
}
// Address
string strAddress = string.Empty;
xmlNodes = xmlNotice.GetElementsByTagName("ecf:CaseParticipantRoleCode[starts-with(text(),'Debtor')]/nc:ContactMailingAddress/nc:StructuredAddress/nc:LocationStreet/nc:StreetFullText");
for (int i = 0; i <= xmlNodes.Count - 1; i++)
{
strAddress = xmlNodes[i].ChildNodes.Item(0).InnerText.Trim();
System.Diagnostics.Debug.WriteLine("Address: " + strAddress);
}
Update: This will give you the list of StructuredAddress
es: 更新:这将为您提供StructuredAddress
列表:
XNamespace ecf = "urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:CommonTypes-4.0";
XNamespace nc = "http://niem.gov/niem/niem-core/2.0";
var xml = XDocument.Load(@"C:\test.xml");
var y = xml.Descendants(ecf + "CaseParticipant").Where(p => p.Descendants(ecf + "CaseParticipantRoleCode").Any(c => c.Value.ToString().TrimEnd() == "Debtor"));
var x = y.Descendants(nc + "StructuredAddress");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.