Get Element Value
|
| Get Element Value | In a loop like so:
... xmlr=cmd.executexmlreader() xmlr.read() do while xmlr.readstate <> xml.readstate.endoffile loop How do I return each individual element name and value from a document like so:
2 Doe John 123 4th st.
So the result I need in the loop is (output to textbox): custno: 2 lname: Doe Thanks a lot.
| | while(reader.Read()) { if(reader.NodeType == XmlNodeType.Element) { _name = reader.Name; if(reader.read()) { if(reader.NodeType == XmlNodeType.Text) { _value = reader.Value; } } } }
or string _name; string _value; while(r.Read()) switch(reader.NodeType) XmlNodeType.Element: _name = reader.Name; break; XmlNodeType.Text: if(_name != null) { _value = reader.Value; _name = null; } // Reset the _name after the value has been found HTH -- Happy Hacking, Gaurav Vaish http://www.mastergaurav.org http://www.edujini.in ------------------- "Jay" wrote in message news:eKDKqhceGHA.1456@TK2MSFTNGP04.phx.gbl... > In a loop like so: > > ... > xmlr=cmd.executexmlreader() > xmlr.read() > do while xmlr.readstate <> xml.readstate.endoffile > loop > How do I return each individual element name and value from a document > like so: > > 2 > Doe > John > 123 4th st. > > So the result I need in the loop is (output to textbox): > custno: 2 > lname: Doe > Thanks a lot. >
| | Thanks for the reply.
This seems to work well, however, I am faced with a problem... I need to get the etire ReadOuterXML for each of the individual records as well as a few of the element values within that record. So with XML like so:
2 Doe John 123 4th st.
3 Smith Terry 456 7th St. I need to return (in a loop) something like this: varOuterXML = "2DoeJohn123 4th st." varLName="Doe" varFName="John" "3SmithTerry456 7th St." varLName="Smith" varFName="Terry" I am using while xmlreader.readstate <> xml.readstate.endoffile but cannot seem to get this to work together. Any suggestions would be greatly appreciated. Thanks a lot. "Gaurav Vaish (EduJini.IN)" wrote in message news:uwY5KejeGHA.968@TK2MSFTNGP04.phx.gbl... > while(reader.Read()) > { > if(reader.NodeType == XmlNodeType.Element) > { > _name = reader.Name; > if(reader.read()) > { > if(reader.NodeType == XmlNodeType.Text) > { > _value = reader.Value; > } > } > } > } > > or > string _name; > string _value; > while(r.Read()) > switch(reader.NodeType) > XmlNodeType.Element: _name = reader.Name; > break; > XmlNodeType.Text: if(_name != null) > { > _value = reader.Value; > _name = null; > } // Reset the _name after the value > has been found > HTH > -- > Happy Hacking, > Gaurav Vaish > http://www.mastergaurav.org > http://www.edujini.in > ------------------- > "Jay" wrote in message > news:eKDKqhceGHA.1456@TK2MSFTNGP04.phx.gbl... >> In a loop like so: >> >> ... >> xmlr=cmd.executexmlreader() >> xmlr.read() >> do while xmlr.readstate <> xml.readstate.endoffile >> loop >> How do I return each individual element name and value from a document >> like so: >> >> 2 >> Doe >> John >> 123 4th st. >> >> So the result I need in the loop is (output to textbox): >> custno: 2 >> lname: Doe >> Thanks a lot. >
| | Don't use single _name and _value. When you encounter an element with the name Customer, jump into another function where you keep track of all entries.
Should be simple. -- Happy Hacking, Gaurav Vaish http://www.mastergaurav.org http://www.edujini.in ------------------- "Jay" wrote in message news:uTwkOlneGHA.4828@TK2MSFTNGP05.phx.gbl... > Thanks for the reply. > > This seems to work well, however, I am faced with a problem... > I need to get the etire ReadOuterXML for each of the individual records as > well as a few of the element values within that record. > So with XML like so: > > 2 > Doe > John > 123 4th st. > > 3 > Smith > Terry > 456 7th St. > I need to return (in a loop) something like this: > varOuterXML = > "2DoeJohn123 > 4th st." > varLName="Doe" > varFName="John" > "3SmithTerry456 > 7th St." > varLName="Smith" > varFName="Terry" > I am using while xmlreader.readstate <> xml.readstate.endoffile but cannot > seem to get this to work together. > Any suggestions would be greatly appreciated. > Thanks a lot. > "Gaurav Vaish (EduJini.IN)" wrote > in message news:uwY5KejeGHA.968@TK2MSFTNGP04.phx.gbl... >> while(reader.Read()) >> { >> if(reader.NodeType == XmlNodeType.Element) >> { >> _name = reader.Name; >> if(reader.read()) >> { >> if(reader.NodeType == XmlNodeType.Text) >> { >> _value = reader.Value; >> } >> } >> } >> } >> >> or >> string _name; >> string _value; >> while(r.Read()) >> switch(reader.NodeType) >> XmlNodeType.Element: _name = reader.Name; >> break; >> XmlNodeType.Text: if(_name != null) >> { >> _value = reader.Value; >> _name = null; >> } // Reset the _name after the value >> has been found >> HTH >> -- >> Happy Hacking, >> Gaurav Vaish >> http://www.mastergaurav.org >> http://www.edujini.in >> ------------------- >> "Jay" wrote in message >> news:eKDKqhceGHA.1456@TK2MSFTNGP04.phx.gbl... >>> In a loop like so: >>> >>> ... >>> xmlr=cmd.executexmlreader() >>> xmlr.read() >>> do while xmlr.readstate <> xml.readstate.endoffile >>> loop >>> How do I return each individual element name and value from a document >>> like so: >>> >>> 2 >>> Doe >>> John >>> 123 4th st. >>> >>> So the result I need in the loop is (output to textbox): >>> custno: 2 >>> lname: Doe >>> Thanks a lot. >
| | Thank you for the reply. Not quite sure what you mean.
I need both the entire outerxml as well as a few individual element values. Would I use a loop inside the loop? "Gaurav Vaish (EduJini.IN)" wrote in message news:ehfnmJqeGHA.4720@TK2MSFTNGP03.phx.gbl... > Don't use single _name and _value. > When you encounter an element with the name Customer, jump into another > function where you keep track of all entries. > > Should be simple. > -- > Happy Hacking, > Gaurav Vaish > http://www.mastergaurav.org > http://www.edujini.in > ------------------- > "Jay" wrote in message > news:uTwkOlneGHA.4828@TK2MSFTNGP05.phx.gbl... >> Thanks for the reply. >> >> This seems to work well, however, I am faced with a problem... >> I need to get the etire ReadOuterXML for each of the individual records >> as well as a few of the element values within that record. >> So with XML like so: >> >> 2 >> Doe >> John >> 123 4th st. >> >> 3 >> Smith >> Terry >> 456 7th St. >> I need to return (in a loop) something like this: >> varOuterXML = >> "2DoeJohn123 >> 4th st." >> varLName="Doe" >> varFName="John" >> "3SmithTerry456 >> 7th St." >> varLName="Smith" >> varFName="Terry" >> I am using while xmlreader.readstate <> xml.readstate.endoffile but >> cannot seem to get this to work together. >> Any suggestions would be greatly appreciated. >> Thanks a lot. >> "Gaurav Vaish (EduJini.IN)" wrote >> in message news:uwY5KejeGHA.968@TK2MSFTNGP04.phx.gbl... >>> while(reader.Read()) >>> { >>> if(reader.NodeType == XmlNodeType.Element) >>> { >>> _name = reader.Name; >>> if(reader.read()) >>> { >>> if(reader.NodeType == XmlNodeType.Text) >>> { >>> _value = reader.Value; >>> } >>> } >>> } >>> } >>> >>> or >>> string _name; >>> string _value; >>> while(r.Read()) >>> switch(reader.NodeType) >>> XmlNodeType.Element: _name = reader.Name; >>> break; >>> XmlNodeType.Text: if(_name != null) >>> { >>> _value = reader.Value; >>> _name = null; >>> } // Reset the _name after the value >>> has been found >>> HTH >>> -- >>> Happy Hacking, >>> Gaurav Vaish >>> http://www.mastergaurav.org >>> http://www.edujini.in >>> ------------------- >>> "Jay" wrote in message >>> news:eKDKqhceGHA.1456@TK2MSFTNGP04.phx.gbl... >>>> In a loop like so: >>>> >>>> ... >>>> xmlr=cmd.executexmlreader() >>>> xmlr.read() >>>> do while xmlr.readstate <> xml.readstate.endoffile >>>> loop >>>> How do I return each individual element name and value from a document >>>> like so: >>>> >>>> 2 >>>> Doe >>>> John >>>> 123 4th st. >>>> >>>> So the result I need in the loop is (output to textbox): >>>> custno: 2 >>>> lname: Doe >>>> Thanks a lot. >
| | You need to keep a track of all the values in a buffer. At the same time, you need to keep storing the individual values.
Similar to what the XmlDocument does. btw, just wondering, why don't you directly use XmlDocument? If the XML file a huge one? -- Happy Hacking, Gaurav Vaish http://www.mastergaurav.org http://www.edujini.in ------------------- "Jay" wrote in message news:%23BT3PbqeGHA.3456@TK2MSFTNGP05.phx.gbl... > Thank you for the reply. Not quite sure what you mean. > > I need both the entire outerxml as well as a few individual element > values. Would I use a loop inside the loop? > "Gaurav Vaish (EduJini.IN)" wrote > in message news:ehfnmJqeGHA.4720@TK2MSFTNGP03.phx.gbl... >> Don't use single _name and _value. >> When you encounter an element with the name Customer, jump into another >> function where you keep track of all entries. >> >> Should be simple. >> -- >> Happy Hacking, >> Gaurav Vaish >> http://www.mastergaurav.org >> http://www.edujini.in >> ------------------- >> "Jay" wrote in message >> news:uTwkOlneGHA.4828@TK2MSFTNGP05.phx.gbl... >>> Thanks for the reply. >>> >>> This seems to work well, however, I am faced with a problem... >>> I need to get the etire ReadOuterXML for each of the individual records >>> as well as a few of the element values within that record. >>> So with XML like so: >>> >>> 2 >>> Doe >>> John >>> 123 4th st. >>> >>> 3 >>> Smith >>> Terry >>> 456 7th St. >>> I need to return (in a loop) something like this: >>> varOuterXML = >>> "2DoeJohn123 >>> 4th st." >>> varLName="Doe" >>> varFName="John" >>> "3SmithTerry456 >>> 7th St." >>> varLName="Smith" >>> varFName="Terry" >>> I am using while xmlreader.readstate <> xml.readstate.endoffile but >>> cannot seem to get this to work together. >>> Any suggestions would be greatly appreciated. >>> Thanks a lot. >>> "Gaurav Vaish (EduJini.IN)" wrote >>> in message news:uwY5KejeGHA.968@TK2MSFTNGP04.phx.gbl... >>>> while(reader.Read()) >>>> { >>>> if(reader.NodeType == XmlNodeType.Element) >>>> { >>>> _name = reader.Name; >>>> if(reader.read()) >>>> { >>>> if(reader.NodeType == XmlNodeType.Text) >>>> { >>>> _value = reader.Value; >>>> } >>>> } >>>> } >>>> } >>>> >>>> or >>>> string _name; >>>> string _value; >>>> while(r.Read()) >>>> switch(reader.NodeType) >>>> XmlNodeType.Element: _name = reader.Name; >>>> break; >>>> XmlNodeType.Text: if(_name != null) >>>> { >>>> _value = reader.Value; >>>> _name = null; >>>> } // Reset the _name after the value >>>> has been found >>>> HTH >>>> -- >>>> Happy Hacking, >>>> Gaurav Vaish >>>> http://www.mastergaurav.org >>>> http://www.edujini.in >>>> ------------------- >>>> "Jay" wrote in message >>>> news:eKDKqhceGHA.1456@TK2MSFTNGP04.phx.gbl... >>>>> In a loop like so: >>>>> >>>>> ... >>>>> xmlr=cmd.executexmlreader() >>>>> xmlr.read() >>>>> do while xmlr.readstate <> xml.readstate.endoffile >>>>> loop >>>>> How do I return each individual element name and value from a document >>>>> like so: >>>>> >>>>> 2 >>>>> Doe >>>>> John >>>>> 123 4th st. >>>>> >>>>> So the result I need in the loop is (output to textbox): >>>>> custno: 2 >>>>> lname: Doe >>>>> Thanks a lot. >
| | The XML I'm using comes from SQL Server 2005 and isn't very large at all. I am having a difficult time with the loop used to capture the individual element values as well as the outerxml. Would you happen to know of an example illustrating this or tutorials on accomplishing this? Thank you very much.
"Gaurav Vaish (EduJini.IN)" wrote in message news:uSMt$KveGHA.5088@TK2MSFTNGP02.phx.gbl... > You need to keep a track of all the values in a buffer. > At the same time, you need to keep storing the individual values. > > Similar to what the XmlDocument does. > btw, just wondering, why don't you directly use XmlDocument? If the XML > file a huge one? > -- > Happy Hacking, > Gaurav Vaish > http://www.mastergaurav.org > http://www.edujini.in > ------------------- > "Jay" wrote in message > news:%23BT3PbqeGHA.3456@TK2MSFTNGP05.phx.gbl... >> Thank you for the reply. Not quite sure what you mean. >> >> I need both the entire outerxml as well as a few individual element >> values. Would I use a loop inside the loop? >> "Gaurav Vaish (EduJini.IN)" wrote >> in message news:ehfnmJqeGHA.4720@TK2MSFTNGP03.phx.gbl... >>> Don't use single _name and _value. >>> When you encounter an element with the name Customer, jump into another >>> function where you keep track of all entries. >>> >>> Should be simple. >>> -- >>> Happy Hacking, >>> Gaurav Vaish >>> http://www.mastergaurav.org >>> http://www.edujini.in >>> ------------------- >>> "Jay" wrote in message >>> news:uTwkOlneGHA.4828@TK2MSFTNGP05.phx.gbl... >>>> Thanks for the reply. >>>> >>>> This seems to work well, however, I am faced with a problem... >>>> I need to get the etire ReadOuterXML for each of the individual records >>>> as well as a few of the element values within that record. >>>> So with XML like so: >>>> >>>> 2 >>>> Doe >>>> John >>>> 123 4th st. >>>> >>>> 3 >>>> Smith >>>> Terry >>>> 456 7th St. >>>> I need to return (in a loop) something like this: >>>> varOuterXML = >>>> "2DoeJohn123 >>>> 4th st." >>>> varLName="Doe" >>>> varFName="John" >>>> "3SmithTerry456 >>>> 7th St." >>>> varLName="Smith" >>>> varFName="Terry" >>>> I am using while xmlreader.readstate <> xml.readstate.endoffile but >>>> cannot seem to get this to work together. >>>> Any suggestions would be greatly appreciated. >>>> Thanks a lot. >>>> "Gaurav Vaish (EduJini.IN)" >>>> wrote in message news:uwY5KejeGHA.968@TK2MSFTNGP04.phx.gbl... >>>>> while(reader.Read()) >>>>> { >>>>> if(reader.NodeType == XmlNodeType.Element) >>>>> { >>>>> _name = reader.Name; >>>>> if(reader.read()) >>>>> { >>>>> if(reader.NodeType == XmlNodeType.Text) >>>>> { >>>>> _value = reader.Value; >>>>> } >>>>> } >>>>> } >>>>> } >>>>> >>>>> or >>>>> string _name; >>>>> string _value; >>>>> while(r.Read()) >>>>> switch(reader.NodeType) >>>>> XmlNodeType.Element: _name = reader.Name; >>>>> break; >>>>> XmlNodeType.Text: if(_name != null) >>>>> { >>>>> _value = reader.Value; >>>>> _name = null; >>>>> } // Reset the _name after the >>>>> value has been found >>>>> HTH >>>>> -- >>>>> Happy Hacking, >>>>> Gaurav Vaish >>>>> http://www.mastergaurav.org >>>>> http://www.edujini.in >>>>> ------------------- >>>>> "Jay" wrote in message >>>>> news:eKDKqhceGHA.1456@TK2MSFTNGP04.phx.gbl... >>>>>> In a loop like so: >>>>>> >>>>>> ... >>>>>> xmlr=cmd.executexmlreader() >>>>>> xmlr.read() >>>>>> do while xmlr.readstate <> xml.readstate.endoffile >>>>>> loop >>>>>> How do I return each individual element name and value from a >>>>>> document like so: >>>>>> >>>>>> 2 >>>>>> Doe >>>>>> John >>>>>> 123 4th st. >>>>>> >>>>>> So the result I need in the loop is (output to textbox): >>>>>> custno: 2 >>>>>> lname: Doe >>>>>> Thanks a lot. >
| | I'd suggest using XmlDocument in that case.
Examples... I'd not be aware. I'm a nerd ;-) -- Happy Hacking, Gaurav Vaish http://www.mastergaurav.org http://www.edujini.in ------------------- wrote in message news:uv%23dVizeGHA.3900@TK2MSFTNGP05.phx.gbl... > The XML I'm using comes from SQL Server 2005 and isn't very large at all. > I am having a difficult time with the loop used to capture the individual > element values as well as the outerxml. Would you happen to know of an > example illustrating this or tutorials on accomplishing this? Thank you > very much. >
|
|
|
|
|
 | Members Area | |
|
 | Last Web Marketing |
|
|
|
|
 | Last Programming Tips |
|
|
|
|
 | Last News |
|
|
|
|
|
|