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

1928 у кіно

Захаров Федір Захарович

Ель Греко