Re: Please help:need to read XML, edit, and write back to XML file
- From: "Steve Yandl" <syandl_nospam@xxxxxxxxxxx>
- Date: Fri, 16 Nov 2007 07:39:39 -0800
Ed,
If you stick with the Scripting FileSystemObject, you can once again read
the entire XML (text) file into a string and then use the 'Replace' function
to replace the tags and text between them with your updated strings. When
you work with text files with the filesystemobject, you open them for
reading, writing or appending. Always keep in mind that if you open the
file for writing, existing text will be overwritten so make sure you back up
your xml files as you test options. The scripting site I directed you to
has scores of other sample scripts that might give you ideas.
You might want to take a look at what Astrid posted in this thread. It
might be an even more efficient way to handle the problem.
Steve
"Ed from AZ" <prof_ofwhat@xxxxxxxxx> wrote in message
news:5e0f01bc-c536-456f-bc3f-0f12af0d73a3@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thank you, Steve!! This got me farther than anything else yet!
And it's perfect - it puts everything in a string with all the tags,
which I can then parse into separate elements and write into an Excel
work*** or a Word table. (Excel may be better, but with some of my
data, Excel's desirte to automatically format cells rather than just
accept whatever comes may be a problem.)
Okay - now comes the fun part:
After I've done all my data manipulations in Word or Excel, I can
write everything back into a string.
Is it then as simple as replacing the original string with the new
string and closing the file?
Ed
On Nov 15, 5:37 pm, "Steve Yandl" <syandl_nos...@xxxxxxxxxxx> wrote:
Ed,
Take a look at this
link.http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct07/h...
The information is for extracting text with a vbScript file but almost
all
of the code can be used in a VBA routine. At the end where they use
WScript.Echo
That is very similar to MsgBox and the variable that comes afterward is
the
text that was pulled from between the tags. I think I'd be inclined to
do
this from a VBA routine in Excel and bring text strings into different
cells
rather than messing with a Word table or multiple paragraphs.
Steve
"Ed from AZ" <prof_ofw...@xxxxxxxxx> wrote in
messagenews:876d3bcb-09ed-4258-ab05-97f29bdad139@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Actually, Steve, I really am (I think!!) just looking for a few tags.
The problem is that when I view the doc in Word, I don't see <tag>text<
\tag>. Instead I see this nice colored autoshape-looking graphic with
"text" in the middle of it.
As I ssaid, I tried iterating through all the paragraphs and trying
different outputs of the Paragraph.Range - .Text, .XMLNode, and so
forth - to see if I could find the tag, but no luck so far.
If I open the XML in NotePad or WordPad, then I see <tag>text<\tag>.
But I don't know how to capture and manipulate that with Word VBA, and
then have the confidence of writing it back into the XML file.
I will search for the MSXML2.DOMDocument and see what I get.
Thanks for the input.
Ed
On Nov 15, 4:19 pm, "Steve Yandl" <syandl_nos...@xxxxxxxxxxx> wrote:
Ed,
If you were only looking for a few tags, it would be simple enough to
parse
out the text strings in a VBA routine using InStr and Mid functions
but I
gather you're dealing with a more complex scenario.
Try doing a web search using the term
MSXML2.DOMDocument
and I think you may find some helpful links with examples of using
that
object within VBA.
Steve
"Ed from AZ" <prof_ofw...@xxxxxxxxx> wrote in
messagenews:65d2f8aa-9dbc-46fb-ad3e-c57bd7019b8e@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm using Word 2003. I use a proprietary Java program that takes
all
the information in the various forms and generates an XML file.
There
are times I need to move information between files. I tried to
explore this in the Excel and Access NG, because the data format
would
lend itself very well to a spread*** or table. But I reached a
dead
end.
My thought is to create a macro that would find the proper tags and
parse out all the data in between the correct tags into a table or
spread***. Then, after I have cut / pasted / mutilated the data
as
required, I can write the new data back into an array, append the
correct tags, and write it back into the original XML file.
One problem is that when I open an XML file in Word 2003, I see on
screen the cute little visual representations of the tags - but they
aren't really there. At least, they don't show up in Print Preview,
and Paragraph.Range.Text doesn't see them. I found a clue in one NG
post and opened the Script Editor (ALT + SHIFT + F11), and saw tags
and much more. But I still have no idea how to accomplish what
seems
to be the simple project of writing out the data from certain tags
and
then writing it back when I'm done.
Can anyone please drop-kick me in a good direction to get started
towards this?
Ed- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
.
- Follow-Ups:
- Re: Please help:need to read XML, edit, and write back to XML file
- From: Ed from AZ
- Re: Please help:need to read XML, edit, and write back to XML file
- References:
- Please help:need to read XML, edit, and write back to XML file
- From: Ed from AZ
- Re: Please help:need to read XML, edit, and write back to XML file
- From: Steve Yandl
- Re: Please help:need to read XML, edit, and write back to XML file
- From: Ed from AZ
- Re: Please help:need to read XML, edit, and write back to XML file
- From: Steve Yandl
- Re: Please help:need to read XML, edit, and write back to XML file
- From: Ed from AZ
- Please help:need to read XML, edit, and write back to XML file
- Prev by Date: Drop Down List Widths
- Next by Date: Re: Please help:need to read XML, edit, and write back to XML file
- Previous by thread: Re: Please help:need to read XML, edit, and write back to XML file
- Next by thread: Re: Please help:need to read XML, edit, and write back to XML file
- Index(es):