parse_article_from_xml

Function parse_article_from_xml 

pub fn parse_article_from_xml(
    xml: &str,
    pmid: &str,
) -> Result<PubMedArticle, ParseError>
Expand description

Parse article from EFetch XML response

Parses a PubMed EFetch XML response and extracts article metadata.

§Arguments

  • xml - The raw XML string from PubMed EFetch API
  • pmid - The PubMed ID of the article to extract

§Returns

A PubMedArticle containing the parsed metadata, or an error if parsing fails.

§Errors

Returns an error if:

  • The XML is malformed or doesn’t match the expected schema
  • The specified PMID is not found in the XML
  • Required fields (like article title) are missing

§Example

use pubmed_client::pubmed::parser::parse_article_from_xml;

let xml = r#"<?xml version="1.0"?>
<PubmedArticleSet>
  <PubmedArticle>
    <MedlineCitation>
      <PMID>12345678</PMID>
      <Article>
        <ArticleTitle>Example Article</ArticleTitle>
        <Journal><Title>Example Journal</Title></Journal>
      </Article>
    </MedlineCitation>
  </PubmedArticle>
</PubmedArticleSet>"#;

let article = parse_article_from_xml(xml, "12345678")?;
assert_eq!(article.title, "Example Article");