|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Updating XML from VB6Basically, I've got an XML file that contains data such as this (sample data, of course): <RootElement> <Row> <Column1>Data1</Column1> <Column2>Data2</Column2> <Column3>Data3</Column3> </Row> <Row> <Column1>Data4</Column1> <Column2>Data5</Column2> <Column3>Data6</Column3> </Row> </RootElement> I need to implement functionality to do two things: 1) Delete a particular "Row" element (and all sub-elements), based on the data in one or more of the Column sub-elements 2) Add a new "Row" element with the three column elements populated At this point, I don't believe I'd need to update existing "Row" elements (other than specified above), and I figure even if I did, I could always read the "Row" into memory, delete the "Row", update the data, and then add it again as a new "Row". What is going to be the easiest way to implement Delete and Add, considering this XML is stored in a file (let's say it's stored at C:\Temp\Data.xml)? Thanks! "Scott M. Lyon" <scott.RED.lyon.WH***@rapistan.BLUE.com> wrote By using MSFT XML parser.> What is going to be the best way to update an XML file from VB6? Add a reference to Microsoft XML 4.0 (or whatever the latest version you have), and check out what it contains using VB's Object Browser. Specificially note what's available in the DOMDocument40 (or whatever the latest...) You'd use CreateElement to create the nodes in the shape you want them, and AppendChild to add them in where they need to go. You might also want to read the docs on RemoveChild and ReplaceChild. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/xmmthremovechild.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/xmmthreplaceChild.asp (They have VB examples) LFS
Show quote
Hide quote
"Scott M. Lyon" <scott.RED.lyon.WH***@rapistan.BLUE.com> wrote in message MS provides a free XML library called MSXML. It has functions for just about news:efY2TDWVFHA.2128@TK2MSFTNGP15.phx.gbl... > What is going to be the best way to update an XML file from VB6? > > > Basically, I've got an XML file that contains data such as this (sample > data, of course): > > <RootElement> > <Row> > <Column1>Data1</Column1> > <Column2>Data2</Column2> > <Column3>Data3</Column3> > </Row> > <Row> > <Column1>Data4</Column1> > <Column2>Data5</Column2> > <Column3>Data6</Column3> > </Row> > </RootElement> > > > I need to implement functionality to do two things: > > 1) Delete a particular "Row" element (and all sub-elements), based on the > data in one or more of the Column sub-elements > 2) Add a new "Row" element with the three column elements populated > > > At this point, I don't believe I'd need to update existing "Row" elements > (other than specified above), and I figure even if I did, I could always > read the "Row" into memory, delete the "Row", update the data, and then > add it again as a new "Row". > > > What is going to be the easiest way to implement Delete and Add, > considering this XML is stored in a file (let's say it's stored at > C:\Temp\Data.xml)? > anything you would want to do with XML. While yuo can manipulate XML using VB's text commands it is not recommended. -- Peter Aitken Remove the crap from my email address before using.
Show quote
Hide quote
> What is going to be the best way to update an XML file from VB6? Select the node you want to kill by using a XPath query, then remove that > > Basically, I've got an XML file that contains data such as this (sample > data, of course): > > <RootElement> > <Row> > <Column1>Data1</Column1> > <Column2>Data2</Column2> > <Column3>Data3</Column3> > </Row> > <Row> > <Column1>Data4</Column1> > <Column2>Data5</Column2> > <Column3>Data6</Column3> > </Row> > </RootElement> > > > I need to implement functionality to do two things: > > 1) Delete a particular "Row" element (and all sub-elements), based on the > data in one or more of the Column sub-elements > 2) Add a new "Row" element with the three column elements populated > > > At this point, I don't believe I'd need to update existing "Row" elements > (other than specified above), and I figure even if I did, I could always > read the "Row" into memory, delete the "Row", update the data, and then > add it again as a new "Row". > > > What is going to be the easiest way to implement Delete and Add, > considering this XML is stored in a file (let's say it's stored at > C:\Temp\Data.xml)? node using RemoveChild() > What is going to be the best way to update an XML file from VB6? <snip>> > Basically, I've got an XML file that contains data such as this (sample > data, of course): Show quoteHide quote > I need to implement functionality to do two things: Use an XPath query to select the node with the contents you're interested > > 1) Delete a particular "Row" element (and all sub-elements), based on the > data in one or more of the Column sub-elements > 2) Add a new "Row" element with the three column elements populated > > At this point, I don't believe I'd need to update existing "Row" elements > (other than specified above), and I figure even if I did, I could always > read the "Row" into memory, delete the "Row", update the data, and then > add it again as a new "Row". > > What is going to be the easiest way to implement Delete and Add, > considering this XML is stored in a file (let's say it's stored at > C:\Temp\Data.xml)? in, then if found remove it: '*** Dim MyDOM As DOMDocument Dim SearchNode As IXMLDOMNode Const FileName As String = "X:\Path\File.xml" Set MyDOM = New DOMDocument MyDOM.async = False If (MyDOM.Load(FileName)) Then Set SearchNode = MyDOM.selectSingleNode( _ "RootElement/Row[Column1/text()=""Data4""]") If (Not (SearchNode Is Nothing)) Then _ Call SearchNode.parentNode.removeChild(SearchNode) Debug.Print MyDOM.xml End If Set MyDOM = Nothing '*** Adding a node is dead easy, simply create some new nodes from the DOM and add them into the appropriate place sin the tree. Here's a link to some old posts of mine on using XML in VB which should answer all your questions on that: http://groups.google.co.uk/group/microsoft.public.vb.general.discussion/msg/c8f73ad9971fd89 Hope this helps, Mike - Microsoft Visual Basic MVP - E-Mail: ED***@mvps.org WWW: Http://EDais.mvps.org/
serial port data loss,i think
Splash Screen and Image Control Problem Referencing User Defined Type from another module Object navigation with <Enter> key stroke Squeezing too much into a control... Combobox, ITEMData and Reselected previous item Use ActiveX DLL in VB.net Rounding Negative Number Toward Zero Dr. Watson "Access violoation" error How to identify and extract bounced email info? |
|||||||||||||||||||||||