AutoitMike Posted March 27, 2022 Posted March 27, 2022 (edited) I am trying to create and append a node that reads like the following: prop name="xxx" type="0" This is what it looks like when using XML viewer. When using notepad (to just view it) it looks like this: <prop name="xxx" type="0">xxx value</prop> For nodes with ordinary names, I have no problem adding nodes, EG: $oOther = $oXML.SelectSingleNode('//xCity') $Node=$oXML.CreateElement('ABC') $oOther.AppendChild($Node) The above works fine. In another program I have no problem reading , selecting and setting these types of nodes, EG: $oOther = $oXML.SelectSingleNode("//xInfo/prop[@name='zzz']") MsgBox(0,"",$oOther.text) $oOther.text="123" Thanks for any help Edited March 27, 2022 by AutoitMike
ad777 Posted March 27, 2022 Posted March 27, 2022 (edited) @AutoitMike well i dont have mush exper with node, but ,if you want to read what inside,use StringRegExp: Edited March 27, 2022 by ad777 none
Nine Posted March 27, 2022 Posted March 27, 2022 (edited) This is what you are looking for, I believe : Local $oNode = $oXML.SelectSingleNode("//Something[@id='1']") ; <<<<<<<< modify accordingly Local $oNew = $oXML.CreateElement("Prop") Local $oName = $oXML.createAttribute("name") $oName.value = "ABC" Local $oType = $oXML.createAttribute("type") $oType.value = "0" $oNode.AppendChild($oNew) With $oNode.lastChild .attributes.setNamedItem($oName) .attributes.setNamedItem($oType) .text = "123" ConsoleWrite("add new tag : " & .xml & @CRLF) EndWith Edited March 27, 2022 by Nine typo “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
AutoitMike Posted March 27, 2022 Author Posted March 27, 2022 (edited) Thanks Nine, I may have miss led you on one item. The parent node is plain, EG: "//ClientList" Then, I need to add the child "Prop name='xxx' type="0" Thanks again Edited March 27, 2022 by AutoitMike Clarify
AutoitMike Posted March 27, 2022 Author Posted March 27, 2022 Nine, I get an error "The requested action with this object has failed." on the line that attempts to appendChild(New) I changed the first line to: Local $oNode = $oXML.SelectSingleNode("//ClientList") This is the parent node Thanks
AutoitMike Posted March 27, 2022 Author Posted March 27, 2022 Nine, I have tried your first line in a few different ways, still fails with the line that appends the new node.
AutoitMike Posted March 27, 2022 Author Posted March 27, 2022 Nine, I am attempting to add the last two nodes in this sample file. Thanks reportxx.hr5
Nine Posted March 27, 2022 Posted March 27, 2022 Run this : Local $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.load("reportxx.hr5") If $oXML.parseError.errorCode Then Exit MsgBox($MB_SYSTEMMODAL, "You have an error", $oXML.parseError.reason) See now ? Error handling is mandatory. Please next time add some. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
AutoitMike Posted March 27, 2022 Author Posted March 27, 2022 I made a change to protect actual data and goofed. Your example works, You rock. Thanks ever so much,
AutoitMike Posted March 28, 2022 Author Posted March 28, 2022 Where is the documentation for these XML functions? Thanks
Nine Posted March 28, 2022 Posted March 28, 2022 https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms764730(v=vs.85) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
AutoitMike Posted March 28, 2022 Author Posted March 28, 2022 Thanks for the link. The documentation is quite overwhelming. Why would an application use this screwy method of defining node names? //ABC/MyNode works pretty well. Is there a specific advantage for “prop name”=“Abc” type=“0” ??
junkew Posted March 28, 2022 Posted March 28, 2022 I think you ask why to use attributes instead of XML elements https://stackoverflow.com/questions/1096797/should-i-use-elements-or-attributes-in-xml FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
AutoitMike Posted March 29, 2022 Author Posted March 29, 2022 junkew, Then the node specification "prop[@name='element name'] " is how to reference a node that has an attribute/s. whereas "//Root/node name" is how you reference a node that has no attributes???
junkew Posted March 29, 2022 Posted March 29, 2022 \\books[price>15] is filtering books on a supplement node price. Screwy method is Just an opinion on what you prefer more yourself. There are many query syntaxis around including was on how to filter FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now