?
Solved

Script  to convert characters in XML file

Posted on 2010-04-08
4
Medium Priority
?
298 Views
Last Modified: 2012-06-21
Hello I have a folder that receives XML files that are pretty uniform across the board but messy I know its possible to edit the XML with VBS from this ipost and many others (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/XML/Q_24756581.html?sfQueryTermInfo=1+edit+script+xml) I have never done this before and needed some help/

I need the following..... Snippet ID=598893

to chop out almost all the info and look allot cleaner like this.....

- <Document>
  <file_number>file number</file_number>
  <case_number>casenumber</case_number>
  <doc_name>W09-265-3811.pdf</doc_name>
  <doc_category>System</doc_category>
  <doc_source>Internal</doc_source>
  <doc_loc>W09-265-3811.pdf</doc_loc>
  <Document>
 
<?xml version="1.0" encoding="utf-8" standalone="no" ?> 
- <!-- ************************************************************
  --> 
- <!-- FILENAME:		K0224021.xml				
  --> 
- <!-- DESCRIPTION:	XML Release document			
  --> 
- <!-- 	 	 	with customizations.			
  --> 
- <!-- LAST MODIFIED:	4/8/2010				
  --> 
- <!-- ************************************************************
  --> 
  <!DOCTYPE kfx:XMLRELEASE (View Source for full doctype...)> 
- <kfx:XMLRELEASE xmlns:kfx="http://www.system.com/dtd/">
- <kfx:KOFAXXML>
- <kfx:BATCHCLASS ID="00000029" NAME="DocID">
- <kfx:DOCUMENTS>
- <kfx:DOCUMENT DOCID="00000EE3" DOCUMENTCLASSNAME="DocID">
- <kfx:DOCUMENTDATA>
  <kfx:DOCUMENTFIELD NAME="file_number" VALUE="W09-265" /> 
  <kfx:DOCUMENTFIELD NAME="case_number" VALUE="casenumber" /> 
  <kfx:DOCUMENTFIELD NAME="doc_name" VALUE="W09-265-3811.pdf" /> 
  <kfx:DOCUMENTFIELD NAME="doc_category" VALUE="CaseAware" /> 
  <kfx:DOCUMENTFIELD NAME="doc_source" VALUE="Internal" /> 
  <kfx:DOCUMENTFIELD NAME="doc_loc" VALUE="W09-265-3811.pdf" /> 
  </kfx:DOCUMENTDATA>
  <kfx:PRIMARYFILES /> 
  <kfx:SECONDARYFILES /> 
  <kfx:OCRTEXTFILES /> 
  </kfx:DOCUMENT>
  </kfx:DOCUMENTS>
  </kfx:BATCHCLASS>
  <kfx:BATCHSTATUS>Complete</kfx:BATCHSTATUS> 
  </kfx:KOFAXXML>
- <prefix:CUSTOMXML xmlns:prefix="www.test.com">
- <prefix:Document>
  <prefix:file_number>file number</prefix:file_number> 
  <prefix:case_number>case number</prefix:case_number> 
  <prefix:doc_name>W09-265-3811.pdf</prefix:doc_name> 
  <prefix:doc_category>system</prefix:doc_category> 
  <prefix:doc_source>Internal</prefix:doc_source> 
  <prefix:doc_loc>W09-265-3811.pdf</prefix:doc_loc> 
  </prefix:Document>
  </prefix:CUSTOMXML>
  </kfx:XMLRELEASE>

Open in new window

0
Comment
Question by:wirbicki2
  • 3
4 Comments
 
LVL 18

Expert Comment

by:exx1976
ID: 30124125
This should do it.  Be sure to test first.

HTH,
exx
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oSource = oFS.OpenTextFile("c:\myxml.xml",1)
Set oTarget = oFS.CreateTextFile("c:\cleanxml.xml")
Write = False
Do While Not oSource.AtEndOfStream
	data = oSource.Readline
	If Write And InStr(LCase(data),"prefix:document") Then
		data = Replace(data,"prefix:","")
		Exit Do
	End If
	If Write Or InStr(LCase(data),"prefix:document") Then
		Write = True
		data = Replace(data,"prefix:","")
		oTarget.WriteLine(data)
	End If
Loop
oSource.Close
oTarget.Close

Open in new window

0
 
LVL 18

Accepted Solution

by:
exx1976 earned 1500 total points
ID: 30124242
Oops..  My apologies.  I forgot to write the last line in target file.  Use this code.

-exx
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oSource = oFS.OpenTextFile("c:\myxml.xml",1)
Set oTarget = oFS.CreateTextFile("c:\cleanxml.xml")
Write = False
Do While Not oSource.AtEndOfStream
	data = oSource.Readline
	If Write And InStr(LCase(data),"prefix:document") Then
		data = Replace(data,"prefix:","")
		oTarget.WriteLine(data)
		Exit Do
	End If
	If Write Or InStr(LCase(data),"prefix:document") Then
		Write = True
		data = Replace(data,"prefix:","")
		oTarget.WriteLine(data)
	End If
Loop
oSource.Close
oTarget.Close

Open in new window

0
 

Author Closing Comment

by:wirbicki2
ID: 31869731
That's awesome thanks that got us on the right track thank you
0
 
LVL 18

Expert Comment

by:exx1976
ID: 31870196
If it's awesome, then why a B?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question