ReadOuterXml Issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stvnegert
    New Member
    • May 2007
    • 4

    ReadOuterXml Issue

    When I try to do the following in a vb.net application:


    [code=vbnet]
    While xtr.Read() And recordCnt < loopCount

    If xtr.NodeType = XmlNodeType.Ele ment Then
    If (xtr.Name = "Employee") Then
    recordCnt = recordCnt + 1
    strWriter = New StringWriter
    UID = ""
    strWriter.Write (xtr.ReadOuterX ml)
    Dim xdoc As New XmlDocument
    'writeObj = CreateObject("M SXML2.DOMDocume nt")


    If docType = "devplan" Then
    xdoc.LoadXml("< ?xml version=""1.0"" encoding=""utf-16"" ?><Batch><Devel opmentPlan>" & strWriter.ToStr ing & "</DevelopmentPlan ></Batch>")
    Else
    xdoc.LoadXml("< ?xml version=""1.0"" encoding=""utf-16"" ?><Batch><Talen tProfile>" & strWriter.ToStr ing & "</TalentProfile></Batch>")
    End If
    End While

    [/code]

    Every other record seems to get skipped when I try to use readouterxml within the while read() loop. Any ideas why this happening or what I can do to fix this issue?

    Thanks.
  • TRScheel
    Recognized Expert Contributor
    • Apr 2007
    • 638

    #2
    Originally posted by stvnegert
    When I try to do the following in a vb.net application:


    [code=vbnet]
    While xtr.Read() And recordCnt < loopCount

    If xtr.NodeType = XmlNodeType.Ele ment Then
    If (xtr.Name = "Employee") Then
    recordCnt = recordCnt + 1
    strWriter = New StringWriter
    UID = ""
    strWriter.Write (xtr.ReadOuterX ml)
    Dim xdoc As New XmlDocument
    'writeObj = CreateObject("M SXML2.DOMDocume nt")


    If docType = "devplan" Then
    xdoc.LoadXml("< ?xml version=""1.0"" encoding=""utf-16"" ?><Batch><Devel opmentPlan>" & strWriter.ToStr ing & "</DevelopmentPlan ></Batch>")
    Else
    xdoc.LoadXml("< ?xml version=""1.0"" encoding=""utf-16"" ?><Batch><Talen tProfile>" & strWriter.ToStr ing & "</TalentProfile></Batch>")
    End If
    End While

    [/code]

    Every other record seems to get skipped when I try to use readouterxml within the while read() loop. Any ideas why this happening or what I can do to fix this issue?

    Thanks.

    Should be a xtr.OuterXML

    ReadOuterXML will advance it if I remember correctly

    Comment

    • stvnegert
      New Member
      • May 2007
      • 4

      #3
      I am using XmlTextReader and Outer XML is not property within this class.

      Comment

      • TRScheel
        Recognized Expert Contributor
        • Apr 2007
        • 638

        #4
        Originally posted by stvnegert
        I am using XmlTextReader and Outer XML is not property within this class.
        I would advise avoiding xmltextreader.. . At least, I really dont like it. Props to you use it. I prefer doing something like this:
        Code:
                Dim SReader As System.IO.StreamReader = New System.IO.StreamReader(filelocation)
                Dim XMLDocument As System.Xml.XmlDocument
                XMLDocument.LoadXml(SReader.ReadToEnd())
                SReader.Close()
        
                'Use XMLDocument from here on out...

        Comment

        Working...