Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get <? tags from xml with vb.net

I am extracting some xml files into a database using vb.net but i am having trouble to identify a line in the xml tag with

The xml looks like that:

<article type="article">
   <id>0103-0002-004</id>
   <?article zz="3100222857"?>
</article>

I am using:

Dim articles As IEnumerable(Of XElement) = docIssues...<article>
For Each article As XElement In articles
   strIdXML = article.Element("id")
   strIdXML = IIf(strIdXML Is Nothing, "element does not exist", strIdXML)

   strGaleId = article.Element("ariticle")
   strGaleId = IIf(strGaleId Is Nothing, "element does not exist", strGaleId)
next

It is fine with the id but i can't manage to get this

Any clues?

Thanks a lot

like image 972
Zifre Avatar asked Dec 04 '25 15:12

Zifre


1 Answers

It's not an element, so accessing it via the Element() function seems wrong. I think that something like:

Dim articlePI = article.DescendantNodes()
  .SingleOrDefault(
       Function(node)
         If Typeof node is XProcessingInstruction
           Dim pi = DirectCast(node,XProcessingInstruction)
           Return pi.Target = "article"
         End If
         Return False
       End Function
  )

to extract the item. You'd then want to cast it to XProcessingInstruction to access it's Data.

like image 199
Damien_The_Unbeliever Avatar answered Dec 07 '25 03:12

Damien_The_Unbeliever



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!