-2

I have a list of graphic names, "graphicList". I need to search my file for each item in the graphicList in an entity string. I don't know how to reference each item in the graphicList and search for it.

Code so far:

    Dim Regex = New Regex("<!ENTITY .*?SYSTEM ""<graphicListItem>"" .*?>")
    Dim strMasterDoc = File.ReadAllText(FileLocation)
    Dim rxMatches = Regex.Matches(strMasterDoc)
    Dim entityList As New List(Of String)

    Dim entityFound As MatchCollection = Regex.Matches(strMasterDoc)

    'For each file's multipled image file references
    For Each m As Match In entityFound
        Dim found As Group = m.Groups(1)
        entityList.Add(found.Value)
    Next
mightymax
  • 431
  • 1
  • 5
  • 16
  • 2
    It looks like you're using regular expressions to parse XML. [Don't do that.](https://stackoverflow.com/a/1732454/150605) You'll have better success if you use the appropriate tool (an XML parser) for the job. – Lance U. Matthews Nov 20 '19 at 18:22
  • @BACON I agree an XML parser would be better. But I'm stuck doing it this way – mightymax Nov 20 '19 at 18:26
  • 1
    @BACON OP had asked [a similar question](https://stackoverflow.com/q/58561174/832052) and it was solved by searching for strings. The XML in question is really SGML which has its own parsers. It was suggested in [a comment](https://stackoverflow.com/questions/58561174/select-text-between-key-words#comment103442399_58561174) to use a SGML parser but OP has not taken that route. – djv Nov 20 '19 at 18:27
  • @djv I don't believe the similar question is similar to this one. I'm asking to use an item in a list to search for within a string containing that item – mightymax Nov 20 '19 at 19:07
  • In JavaScript I load the graphicNames into an array then search for the entity containing the array item. Wouldn't the same apply to .NET lists? – mightymax Nov 20 '19 at 19:14
  • @MaxineHammett it is similar in that you are 1. parsing xml as text, instead of using an xml parser; 2. it appears to be SGML again, so a standard xml parser wouldn't suffice. I was addressing BACON's comment that using an XML parser would be better by linking to the other question where you have elected not to. Hope this clears it up. Glad you solved it. – djv Nov 20 '19 at 21:57

1 Answers1

0

I found the answer to my question

        For Each item As Match In graphicRefList
          Dim found As Group = item.Groups(1)
          GraphicList.Add(found.Value)
          Dim Regex = New Regex("(<!ENTITY " & found.Value & " SYSTEM ""\w.+?\w"" .*?>)")
        Next
mightymax
  • 431
  • 1
  • 5
  • 16