Results 1 to 3 of 3

Thread: Very weird string problem

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    48

    Very weird string problem

    I have a VERY annoying string problem. I am importing an XML file and trying to read whats in between the tags. this is the last tag I have left and it doesn't make sense. This is a small clip of what is read from the file

    Code:
     <cp:revision>1</cp:revision> 
      <dcterms:created xsi:type="dcterms:W3CDTF">2009-03-18T16:03:00Z</dcterms:created> 
      <dcterms:modified xsi:type="dcterms:W3CDTF">2009-03-18T16:45:00Z</dcterms:modified> 
      </cp:coreProperties>
    This is the code I'm using to get whats between the dcterms:created tags
    Code:
            tagStart = "<dcterms:created"
            tagEnd = "</dcterms:created"
            x = input.IndexOf(tagStart)
            y = input.IndexOf(tagEnd)
            If x = -1 Or y = -1 Then MessageBox.Show("iFailed")
            Info.datecreated = input.Substring(x + 43, y - x)
            Info.timecreated = input.Substring(x + 54, y - x)
    but I get all this extra.

    Code:
    2009-03-18T16:03:00Z</dcterms:created><dcterms:modified xsi:typ
    
    16:03:00Z</dcterms:created><dcterms:modified xsi:type="dcterms:
    Why do i get so much extra stuff.

    P.S. someone pointed me at the System.XML and i looked at it but im not entirely sure how to use it. I am still very new at programming. plus I have gotten so far doing it my way

  2. #2
    Addicted Member
    Join Date
    Jul 2009
    Posts
    140

    Re: Very weird string problem

    seems like it should have been
    Code:
     input.Substring(x + 43, y - (x+43))
    input.Substring(x + 54, y - (x+54))
    If you found my reply helpful, please rate me

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Very weird string problem

    Yeah, you really shouldn't be using string manipulation to work with XML. .NET has extensive support for XML handling so that's what you should use. Probably the easiest way to do this would be to create an XmlDocument, which is a member of System.Xml, and then pick out the individual elements you need. You should start by reading the documentation for the XmlDocument class and then search the web for examples. You can then give it a go and, if you have issues, post back here with what you've done and an explanation of the current problem.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width