PatentGetterController.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using Microsoft.AspNetCore.Mvc;
  2. using System.Reflection.Emit;
  3. using System.Xml;
  4. using System.Xml.Linq;
  5. namespace AddressPaser.Controllers
  6. {
  7. [Route("api/[controller]/[action]")]
  8. [ApiController]
  9. public class PatentGetterController : ControllerBase
  10. {
  11. [HttpGet(Name = "GetPatentbyAppNo")]
  12. public List<string> GetPatentbyAppNo(string appNo)
  13. {
  14. IPRS.xiaoshi.sz.com.IPRSSearcher searcher = new IPRS.xiaoshi.sz.com.IPRSSearcher();
  15. string retXml = searcher.GetPatentFullTxtInfo(appNo);
  16. List<string> technicalFieldTexts = new List<string>();
  17. XmlDocument xmlDoc = new XmlDocument();
  18. xmlDoc.LoadXml(retXml);
  19. XmlNamespaceManager nsManager = new XmlNamespaceManager(xmlDoc.NameTable);
  20. nsManager.AddNamespace("business", "http://www.sipo.gov.cn/XMLSchema/business");
  21. nsManager.AddNamespace("base", "http://www.sipo.gov.cn/XMLSchema/base");
  22. // XPath to find all <p> tags within <technical-field>
  23. XmlNodeList TNodes = xmlDoc.SelectNodes("//cn-patent-document/application-body/description/technical-field/p");
  24. if (TNodes != null)
  25. {
  26. if (TNodes.Count != 0)
  27. {
  28. foreach (XmlNode pNode in TNodes)
  29. {
  30. // Extract the text content of each <p> tag
  31. technicalFieldTexts.Add(pNode.InnerText.Trim());
  32. }
  33. }
  34. else
  35. {
  36. // 选择所有 business:Description 下的 base:Paragraphs 节点
  37. XmlNodeList paragraphs = xmlDoc.DocumentElement.SelectNodes("//business:Description/base:Paragraphs",
  38. nsManager
  39. );
  40. // 遍历节点提取内容
  41. foreach (XmlNode para in paragraphs)
  42. {
  43. technicalFieldTexts.Add(para.InnerText);
  44. }
  45. }
  46. }
  47. // XPath to find all <p> tags within <technical-field>
  48. XmlNodeList BNodes = xmlDoc.SelectNodes("//cn-patent-document/application-body/description/background-art/p");
  49. if (TNodes != null)
  50. {
  51. foreach (XmlNode pNode in BNodes)
  52. {
  53. // Extract the text content of each <p> tag
  54. technicalFieldTexts.Add(pNode.InnerText.Trim());
  55. }
  56. }
  57. // XPath to find all <p> tags within <technical-field>
  58. XmlNodeList DNodes = xmlDoc.SelectNodes("//cn-patent-document/application-body/description/disclosure/p");
  59. if (TNodes != null)
  60. {
  61. foreach (XmlNode pNode in DNodes)
  62. {
  63. // Extract the text content of each <p> tag
  64. technicalFieldTexts.Add(pNode.InnerText.Trim());
  65. }
  66. }
  67. // XPath to find all <p> tags within <technical-field>
  68. XmlNodeList MNodes = xmlDoc.SelectNodes("//cn-patent-document/application-body/description/mode-for-invention/p");
  69. if (TNodes != null)
  70. {
  71. foreach (XmlNode pNode in MNodes)
  72. {
  73. // Extract the text content of each <p> tag
  74. technicalFieldTexts.Add(pNode.InnerText.Trim());
  75. }
  76. }
  77. if(technicalFieldTexts.Count == 0)
  78. {
  79. // XPath to find all <p> tags within <technical-field>
  80. XmlNodeList desNodes = xmlDoc.SelectNodes("//cn-patent-document/application-body/description/p");
  81. if (TNodes != null)
  82. {
  83. foreach (XmlNode pNode in desNodes)
  84. {
  85. // Extract the text content of each <p> tag
  86. technicalFieldTexts.Add(pNode.InnerText.Trim());
  87. }
  88. }
  89. }
  90. return technicalFieldTexts;
  91. }
  92. }
  93. }