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("Co ntent");
varOutputString = (reader.ReadElementContent AsString() );
The xml file below has two different mimeType
in the Attachments node
1: <mimeType>application/pdf<
2: <mimeType>application/pdf<
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("Co
varOutputString = (reader.ReadElementContent
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());
}
<?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>
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi carl_tawn
May I see how you solution might look like?
May I see how you solution might look like?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Solve my problem