VBA - Overwrite XML property of MSXML2.DOMDocumentHow can I use vba to modify xml declarationsHow does one parse XML files?What characters do I need to escape in XML documents?How do I set the encoding statement in the XML declaration when performing an XSL transformation using a COM Msxml2.XSLTemplate?How do I parse XML in Python?How do I comment out a block of tags in XML?What does <![CDATA[]]> in XML mean?How Do You Parse and Process HTML/XML in PHP?How to avoid using Select in Excel VBAexcel replace function in access vbaConvert xml contents to a key value pair in C#

Store Credit Card Information in Password Manager?

Count the occurrence of each unique word in the file

Did arcade monitors have same pixel aspect ratio as TV sets?

Can I sign legal documents with a smiley face?

Yosemite Fire Rings - What to Expect?

On a tidally locked planet, would time be quantized?

How much character growth crosses the line into breaking the character

What does chmod -u do?

Problem with TransformedDistribution

Which one is correct as adjective “protruding” or “protruded”?

Are paving bricks differently sized for sand bedding vs mortar bedding?

How to implement a feedback to keep the DC gain at zero for this conceptual passive filter?

Is it possible to have a strip of cold climate in the middle of a planet?

When were female captains banned from Starfleet?

How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?

How can Trident be so inexpensive? Will it orbit Triton or just do a (slow) flyby?

Open a doc from terminal, but not by its name

Creepy dinosaur pc game identification

Create all possible words using a set or letters

Closed-form expression for certain product

Is there a name for this algorithm to calculate the concentration of a mixture of two solutions containing the same solute?

Why Shazam when there is already Superman?

Freedom of speech and where it applies

2.8 Why are collections grayed out? How can I open them?



VBA - Overwrite XML property of MSXML2.DOMDocument


How can I use vba to modify xml declarationsHow does one parse XML files?What characters do I need to escape in XML documents?How do I set the encoding statement in the XML declaration when performing an XSL transformation using a COM Msxml2.XSLTemplate?How do I parse XML in Python?How do I comment out a block of tags in XML?What does <![CDATA[]]> in XML mean?How Do You Parse and Process HTML/XML in PHP?How to avoid using Select in Excel VBAexcel replace function in access vbaConvert xml contents to a key value pair in C#













1















I have the following subroutine where I want to loop through an XML document and overwrite specific nodes. There is a Range in Excel where I've already constructed the xml string exactly as I need it. Is there an easy way to just set the xml property the same way I can overwrite the text property? I tried to go the MSXML route to make it easier to traverse the dom but in this case it might just be easier to traverse the text file line by line unless someone knows an easy way to do this. I realize I could loop through the child nodes and individually set the <V> tags but that has other challenges and it seems more effort then it is worth.



Sub TestXML()
Dim path As String: path = Range("FilePath")
Dim XDoc As Object, root As Object

Set XDoc = CreateObject("MSXML2.DOMDocument")
XDoc.async = False: XDoc.validateOnParse = False
XDoc.Load (path)

Dim Nodes As Variant: Set Nodes = XDoc.SelectNodes("//P")
Dim NodeLength As Integer: NodeLength = Nodes.Length

For Each listnode In Nodes
//This works but does not format correctly
listnode.text = "<P><D>Bob</D><V>Lob</V><V>law</V></P>"
//This throws a Run-time error 450 wrong number of arguments or invalid property assignment
listnode.xml = "<P><D>Bob</D><V>Lob</V><V>law</V></P>"
Next listnode

XDoc.Save Range("FilePath")
Set XDoc = Nothing
End Sub









share|improve this question
























  • stackoverflow.com/a/11696312/62576

    – Ken White
    Mar 13 at 0:36











  • Hi Ken, I am aware that I can access the child elements with childNodes.item(). My question is can I overwrite the parent node without having to loop through and update every child node. In this case I have about 50 child nodes in the <V> tags that are already formatted properly in Excel.

    – kayzej1141
    Mar 18 at 15:12















1















I have the following subroutine where I want to loop through an XML document and overwrite specific nodes. There is a Range in Excel where I've already constructed the xml string exactly as I need it. Is there an easy way to just set the xml property the same way I can overwrite the text property? I tried to go the MSXML route to make it easier to traverse the dom but in this case it might just be easier to traverse the text file line by line unless someone knows an easy way to do this. I realize I could loop through the child nodes and individually set the <V> tags but that has other challenges and it seems more effort then it is worth.



Sub TestXML()
Dim path As String: path = Range("FilePath")
Dim XDoc As Object, root As Object

Set XDoc = CreateObject("MSXML2.DOMDocument")
XDoc.async = False: XDoc.validateOnParse = False
XDoc.Load (path)

Dim Nodes As Variant: Set Nodes = XDoc.SelectNodes("//P")
Dim NodeLength As Integer: NodeLength = Nodes.Length

For Each listnode In Nodes
//This works but does not format correctly
listnode.text = "<P><D>Bob</D><V>Lob</V><V>law</V></P>"
//This throws a Run-time error 450 wrong number of arguments or invalid property assignment
listnode.xml = "<P><D>Bob</D><V>Lob</V><V>law</V></P>"
Next listnode

XDoc.Save Range("FilePath")
Set XDoc = Nothing
End Sub









share|improve this question
























  • stackoverflow.com/a/11696312/62576

    – Ken White
    Mar 13 at 0:36











  • Hi Ken, I am aware that I can access the child elements with childNodes.item(). My question is can I overwrite the parent node without having to loop through and update every child node. In this case I have about 50 child nodes in the <V> tags that are already formatted properly in Excel.

    – kayzej1141
    Mar 18 at 15:12













1












1








1








I have the following subroutine where I want to loop through an XML document and overwrite specific nodes. There is a Range in Excel where I've already constructed the xml string exactly as I need it. Is there an easy way to just set the xml property the same way I can overwrite the text property? I tried to go the MSXML route to make it easier to traverse the dom but in this case it might just be easier to traverse the text file line by line unless someone knows an easy way to do this. I realize I could loop through the child nodes and individually set the <V> tags but that has other challenges and it seems more effort then it is worth.



Sub TestXML()
Dim path As String: path = Range("FilePath")
Dim XDoc As Object, root As Object

Set XDoc = CreateObject("MSXML2.DOMDocument")
XDoc.async = False: XDoc.validateOnParse = False
XDoc.Load (path)

Dim Nodes As Variant: Set Nodes = XDoc.SelectNodes("//P")
Dim NodeLength As Integer: NodeLength = Nodes.Length

For Each listnode In Nodes
//This works but does not format correctly
listnode.text = "<P><D>Bob</D><V>Lob</V><V>law</V></P>"
//This throws a Run-time error 450 wrong number of arguments or invalid property assignment
listnode.xml = "<P><D>Bob</D><V>Lob</V><V>law</V></P>"
Next listnode

XDoc.Save Range("FilePath")
Set XDoc = Nothing
End Sub









share|improve this question
















I have the following subroutine where I want to loop through an XML document and overwrite specific nodes. There is a Range in Excel where I've already constructed the xml string exactly as I need it. Is there an easy way to just set the xml property the same way I can overwrite the text property? I tried to go the MSXML route to make it easier to traverse the dom but in this case it might just be easier to traverse the text file line by line unless someone knows an easy way to do this. I realize I could loop through the child nodes and individually set the <V> tags but that has other challenges and it seems more effort then it is worth.



Sub TestXML()
Dim path As String: path = Range("FilePath")
Dim XDoc As Object, root As Object

Set XDoc = CreateObject("MSXML2.DOMDocument")
XDoc.async = False: XDoc.validateOnParse = False
XDoc.Load (path)

Dim Nodes As Variant: Set Nodes = XDoc.SelectNodes("//P")
Dim NodeLength As Integer: NodeLength = Nodes.Length

For Each listnode In Nodes
//This works but does not format correctly
listnode.text = "<P><D>Bob</D><V>Lob</V><V>law</V></P>"
//This throws a Run-time error 450 wrong number of arguments or invalid property assignment
listnode.xml = "<P><D>Bob</D><V>Lob</V><V>law</V></P>"
Next listnode

XDoc.Save Range("FilePath")
Set XDoc = Nothing
End Sub






xml vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 12 at 20:11









Mr Lister

35.3k1077121




35.3k1077121










asked Mar 7 at 7:38









kayzej1141kayzej1141

155




155












  • stackoverflow.com/a/11696312/62576

    – Ken White
    Mar 13 at 0:36











  • Hi Ken, I am aware that I can access the child elements with childNodes.item(). My question is can I overwrite the parent node without having to loop through and update every child node. In this case I have about 50 child nodes in the <V> tags that are already formatted properly in Excel.

    – kayzej1141
    Mar 18 at 15:12

















  • stackoverflow.com/a/11696312/62576

    – Ken White
    Mar 13 at 0:36











  • Hi Ken, I am aware that I can access the child elements with childNodes.item(). My question is can I overwrite the parent node without having to loop through and update every child node. In this case I have about 50 child nodes in the <V> tags that are already formatted properly in Excel.

    – kayzej1141
    Mar 18 at 15:12
















stackoverflow.com/a/11696312/62576

– Ken White
Mar 13 at 0:36





stackoverflow.com/a/11696312/62576

– Ken White
Mar 13 at 0:36













Hi Ken, I am aware that I can access the child elements with childNodes.item(). My question is can I overwrite the parent node without having to loop through and update every child node. In this case I have about 50 child nodes in the <V> tags that are already formatted properly in Excel.

– kayzej1141
Mar 18 at 15:12





Hi Ken, I am aware that I can access the child elements with childNodes.item(). My question is can I overwrite the parent node without having to loop through and update every child node. In this case I have about 50 child nodes in the <V> tags that are already formatted properly in Excel.

– kayzej1141
Mar 18 at 15:12












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55038422%2fvba-overwrite-xml-property-of-msxml2-domdocument%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55038422%2fvba-overwrite-xml-property-of-msxml2-domdocument%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved