Link to home
Start Free TrialLog in
Avatar of ZURINET
ZURINET

asked on

using XmlReader reader to extract an elemen in correlation with another element

Hi all
The xml file below has two different mimeType
in the Attachments node
1:  <mimeType>application/pdf</mimeType>
 2: <mimeType>application/pdf</mimeType>
I am looking for a way to get the value in content If and only if the value of mimeType
is "application/pdf"

Thanks in Advance


If (mimeType = "application/pdf")
    reader.ReadToFollowing("Content");
    varOutputString = (reader.ReadElementContentAsString());


using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
{
    reader.ReadToFollowing("attachment");
    reader.MoveToFirstAttribute();
    string genre = reader.Value;
   
If (mimeType = "application/pdf")
    reader.ReadToFollowing("Content");
    varOutputString = (reader.ReadElementContentAsString());
}

Open in new window




<?xml version="1.0" encoding="iso-8859-1"?>
<XMLEnvelope>
  <Header>
    <SenderID>950001</SenderID>
    <ReceiverID>001</ReceiverID>
    <DocumentID>MacDonals</DocumentID>
    <DocumentStandard>UNEDIFACT</DocumentStandard>
    <DocumentType>Invoice</DocumentType>
  </Header>
  <Data>
    <Content><![CDATA[UNA:+68']]></Content>
    <Attachments>
      <Content>JVBERi0xLjQgolJUVPRgo=</Content>
      <mimeType>application/pdf</mimeType>
      <Filename>Invoice.pdf</Filename>
      <Size>47180</Size>
      <Description></Description>
    </Attachments>
    <Attachments>
      <Content>PD94bWwgdmVycRvY29sPg==</Content>
      <mimeType>x-application/log</mimeType>
      <Filename>log.xml</Filename>
      <Size>3610</Size>
      <Description>Validation Result</Description>
    </Attachments>
  </Data>
</XMLEnvelope>

Open in new window

Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

This seems like something that would be more easily achieved using an XmlDocument and an XPath expression. Is that something you're open to, or do you specifically need to use an XmlReader?
SOLUTION
Avatar of ZURINET
ZURINET

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ZURINET
ZURINET

ASKER

Hi carl_tawn

May I see how you solution might look like?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ZURINET

ASKER

Solve my problem