locked
String Function RRS feed

  • Question

  • User-1738841732 posted

    I have...

    Dim strXML as string="<NewDataSet>
    <USPWEB>
    <NUMBER>4112344112344113</NUMBER>
    <CTYPE>VI</CTYPE>
    <EXPIRATION>0623</EXPIRATION>
    <ACCOUNT>2036220196290</ACCOUNT>
    <STATUS>A</STATUS>
    <DEFAULT>N</DEFAULT>
    <TYPE>R</TYPE>
    <DATE>2016-04-11T11:02:13-04:00</DATE>
    <ACCOUNTREFID>100001</ACCOUNTREFID>
    <NTITY>BILLPAY</NTITY>
    <STRRETVAL>99</STRRETVAL>
    </USPWEB>
    </NewDataSet>"


    Now I want a function(strXML.<someFunction>) where I can find the value for STRRETVAL is 99

    *STRRETVAL  May be or may not be, we have to check first if it exists
    * STRRETVAL can have any number or character

    Monday, February 11, 2019 6:14 PM

All replies

  • User-474980206 posted

    pretty simple in javascript/jquery

    // xml literal format requires ES6
    var xml = `<NewDataSet>
     <USPWEB>
      <NUMBER>4112344112344113</NUMBER>
      <CTYPE>VI</CTYPE>
      <EXPIRATION>0623</EXPIRATION>
      <ACCOUNT>2036220196290</ACCOUNT>
      <STATUS>A</STATUS>
      <DEFAULT>N</DEFAULT>
      <TYPE>R</TYPE>
      <DATE>2016-04-11T11:02:13-04:00</DATE>
      <ACCOUNTREFID>100001</ACCOUNTREFID>
      <NTITY>BILLPAY</NTITY>
      <STRRETVAL>99</STRRETVAL>
     </USPWEB>
    </NewDataSet>
    `;
    
    var $xml = $($.parseXML(xml));
    alert($xml.find("USPWEB").find("STRRETVAL").text());
    


    :

    Monday, February 11, 2019 8:05 PM
  • User-1738841732 posted

    I have to do this in code behind, I cannot implement jQuerry :(

    Can u please give me code behind logic

    Monday, February 11, 2019 8:53 PM
  • User475983607 posted

    mansooraabid

    I have to do this in code behind, I cannot implement jQuerry :(

    Can u please give me code behind logic

    .NET has quite extensive openly published and extremely easy to find XML support.  I type VB XML in an internet search and founds these excellent docs.

    https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/xml/

    https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/xml/manipulating-xml

    https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/concepts/linq/parsing-xml

    The links above deal with XML directly but most of the time developers want to deserialize XML into a type similar to the previous post only on the server.  This stuff is also openly published.

    Imports Newtonsoft
    Imports Newtonsoft.Json
    Imports Newtonsoft.Json.Linq
    Imports System
    Imports System.IO
    Imports System.Security.Cryptography
    Imports System.Xml.Serialization
    
    Module Module1
    
        Sub Main()
    
            Dim strXML As String = "<NewDataSet>
                                        <USPWEB>
                                            <NUMBER>4112344112344113</NUMBER>
                                            <CTYPE>VI</CTYPE>
                                            <EXPIRATION>0623</EXPIRATION>
                                            <ACCOUNT>2036220196290</ACCOUNT>
                                            <STATUS>A</STATUS>
                                            <DEFAULT>N</DEFAULT>
                                            <TYPE>R</TYPE>
                                            <DATE>2016-04-11T11:02:13-04:00</DATE>
                                            <ACCOUNTREFID>100001</ACCOUNTREFID>
                                            <NTITY>BILLPAY</NTITY>
                                            <STRRETVAL>99</STRRETVAL>
                                        </USPWEB>
                                    </NewDataSet>"
    
    
            Dim serializer As XmlSerializer = New XmlSerializer(GetType(NewDataSet))
            Using reader As New StringReader(strXML)
                Dim ds As NewDataSet = serializer.Deserialize(reader)
                Console.WriteLine(ds.USPWEB.ACCOUNT)
            End Using
        End Sub
    
    
    
    
    End Module
    
    <System.SerializableAttribute(), _
     System.ComponentModel.DesignerCategoryAttribute("code"), _
     System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True), _
     System.Xml.Serialization.XmlRootAttribute([Namespace]:="", IsNullable:=False)> _
    Partial Public Class NewDataSet
    
        Private uSPWEBField As NewDataSetUSPWEB
    
        '''<remarks/>
        Public Property USPWEB() As NewDataSetUSPWEB
            Get
                Return Me.uSPWEBField
            End Get
            Set
                Me.uSPWEBField = Value
            End Set
        End Property
    End Class
    
    '''<remarks/>
    <System.SerializableAttribute(), _
     System.ComponentModel.DesignerCategoryAttribute("code"), _
     System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)> _
    Partial Public Class NewDataSetUSPWEB
    
        Private nUMBERField As ULong
    
        Private cTYPEField As String
    
        Private eXPIRATIONField As UShort
    
        Private aCCOUNTField As ULong
    
        Private sTATUSField As String
    
        Private dEFAULTField As String
    
        Private tYPEField As String
    
        Private dATEField As Date
    
        Private aCCOUNTREFIDField As UInteger
    
        Private nTITYField As String
    
        Private sTRRETVALField As Byte
    
        '''<remarks/>
        Public Property NUMBER() As ULong
            Get
                Return Me.nUMBERField
            End Get
            Set
                Me.nUMBERField = Value
            End Set
        End Property
    
        '''<remarks/>
        Public Property [CTYPE]() As String
            Get
                Return Me.cTYPEField
            End Get
            Set
                Me.cTYPEField = Value
            End Set
        End Property
    
        '''<remarks/>
        Public Property EXPIRATION() As UShort
            Get
                Return Me.eXPIRATIONField
            End Get
            Set
                Me.eXPIRATIONField = Value
            End Set
        End Property
    
        '''<remarks/>
        Public Property ACCOUNT() As ULong
            Get
                Return Me.aCCOUNTField
            End Get
            Set
                Me.aCCOUNTField = Value
            End Set
        End Property
    
        '''<remarks/>
        Public Property STATUS() As String
            Get
                Return Me.sTATUSField
            End Get
            Set
                Me.sTATUSField = Value
            End Set
        End Property
    
        '''<remarks/>
        Public Property [DEFAULT]() As String
            Get
                Return Me.dEFAULTField
            End Get
            Set
                Me.dEFAULTField = Value
            End Set
        End Property
    
        '''<remarks/>
        Public Property TYPE() As String
            Get
                Return Me.tYPEField
            End Get
            Set
                Me.tYPEField = Value
            End Set
        End Property
    
        '''<remarks/>
        Public Property [DATE]() As Date
            Get
                Return Me.dATEField
            End Get
            Set
                Me.dATEField = Value
            End Set
        End Property
    
        '''<remarks/>
        Public Property ACCOUNTREFID() As UInteger
            Get
                Return Me.aCCOUNTREFIDField
            End Get
            Set
                Me.aCCOUNTREFIDField = Value
            End Set
        End Property
    
        '''<remarks/>
        Public Property NTITY() As String
            Get
                Return Me.nTITYField
            End Get
            Set
                Me.nTITYField = Value
            End Set
        End Property
    
        '''<remarks/>
        Public Property STRRETVAL() As Byte
            Get
                Return Me.sTRRETVALField
            End Get
            Set
                Me.sTRRETVALField = Value
            End Set
        End Property
    End Class
    
    

    https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/concepts/linq/how-to-serialize-using-xmlserializer

    https://docs.microsoft.com/en-us/dotnet/api/system.xml.serialization.xmlserializer.deserialize?view=netframework-4.7.2

    Monday, February 11, 2019 9:16 PM
  • User-474980206 posted

    I have to do this in code behind, I cannot implement jQuerry :(

    Can u please give me code behind logic

    then do not ask in jQuery forum. if you have code behind, then its probably should be asked in the  web form forum.

    Monday, February 11, 2019 11:48 PM
  • User-2054057000 posted

    I have to do this in code behind, I cannot implement jQuerry :(

    Can u please give me code behind logic

    You add jQuery from CDN and it will start working.

    Sunday, February 24, 2019 1:09 PM