using Microsoft.AspNetCore.Mvc; using System.Reflection.Emit; using System.Xml; using System.Xml.Linq; namespace AddressPaser.Controllers { [Route("api/[controller]/[action]")] [ApiController] public class PatentGetterController : ControllerBase { [HttpGet(Name = "GetPatentbyAppNo")] public List GetPatentbyAppNo(string appNo) { IPRS.xiaoshi.sz.com.IPRSSearcher searcher = new IPRS.xiaoshi.sz.com.IPRSSearcher(); string retXml = searcher.GetPatentFullTxtInfo(appNo); List technicalFieldTexts = new List(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(retXml); XmlNamespaceManager nsManager = new XmlNamespaceManager(xmlDoc.NameTable); nsManager.AddNamespace("business", "http://www.sipo.gov.cn/XMLSchema/business"); nsManager.AddNamespace("base", "http://www.sipo.gov.cn/XMLSchema/base"); // XPath to find all

tags within XmlNodeList TNodes = xmlDoc.SelectNodes("//cn-patent-document/application-body/description/technical-field/p"); if (TNodes != null) { if (TNodes.Count != 0) { foreach (XmlNode pNode in TNodes) { // Extract the text content of each

tag technicalFieldTexts.Add(pNode.InnerText.Trim()); } } else { // 选择所有 business:Description 下的 base:Paragraphs 节点 XmlNodeList paragraphs = xmlDoc.DocumentElement.SelectNodes("//business:Description/base:Paragraphs", nsManager ); // 遍历节点提取内容 foreach (XmlNode para in paragraphs) { technicalFieldTexts.Add(para.InnerText); } } } // XPath to find all

tags within XmlNodeList BNodes = xmlDoc.SelectNodes("//cn-patent-document/application-body/description/background-art/p"); if (TNodes != null) { foreach (XmlNode pNode in BNodes) { // Extract the text content of each

tag technicalFieldTexts.Add(pNode.InnerText.Trim()); } } // XPath to find all

tags within XmlNodeList DNodes = xmlDoc.SelectNodes("//cn-patent-document/application-body/description/disclosure/p"); if (TNodes != null) { foreach (XmlNode pNode in DNodes) { // Extract the text content of each

tag technicalFieldTexts.Add(pNode.InnerText.Trim()); } } // XPath to find all

tags within XmlNodeList MNodes = xmlDoc.SelectNodes("//cn-patent-document/application-body/description/mode-for-invention/p"); if (TNodes != null) { foreach (XmlNode pNode in MNodes) { // Extract the text content of each

tag technicalFieldTexts.Add(pNode.InnerText.Trim()); } } if(technicalFieldTexts.Count == 0) { // XPath to find all

tags within XmlNodeList desNodes = xmlDoc.SelectNodes("//cn-patent-document/application-body/description/p"); if (TNodes != null) { foreach (XmlNode pNode in desNodes) { // Extract the text content of each

tag technicalFieldTexts.Add(pNode.InnerText.Trim()); } } } return technicalFieldTexts; } } }