Solved

Removing statements from xml files

Posted on 2007-04-10
5
153 Views
Last Modified: 2010-04-23
Hello Experts,

I have to remove below mentioned statements from xml files....there are multiple types of such statements..


1. <?xml:stylesheet type="text/xsl" href="../../home.xsl" ?>
2. <?xml:stylesheet type="text/xsl" href="../../page.xsl" ?>

also there are attributes such as below...there are multiple xsd's which needs to remove with attribute.

1. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2. xsi:noNamespaceSchemaLocation="../../home.xsd"
3. xsi:noNamespaceSchemaLocation="../../page.xsd"


Is there any way to implement such type of task using vb.net? or any references for the same?

Thanks,
Shailesh
0
Comment
Question by:ShaileshShinde
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 24

Expert Comment

by:fridom
ID: 18887714
Why not? Just read it line by line and compart it to the string you like to install, then write out another file with the stuff you want deleted beeing ommitted.

Regards
Friedrich
0
 
LVL 1

Author Comment

by:ShaileshShinde
ID: 18887803
Hello Expert,

I am doing something like this....

Private Sub cmdPreProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPreProcess.Click
        Dim mydir As New DirectoryInfo(mstrFolderXMLFiles)
        mydir = New DirectoryInfo(mstrFolderXMLFiles)
        WorkWithDirectory(mydir)
    End Sub
    Public Shared Sub WorkWithDirectory(ByVal aDir As DirectoryInfo)
        Dim nextDir As DirectoryInfo
        WorkWithFilesInDir(aDir)
        For Each nextDir In aDir.GetDirectories
            WorkWithDirectory(nextDir)
        Next
    End Sub
    Public Shared Sub WorkWithFilesInDir(ByVal aDir As DirectoryInfo)
        Dim aFile As FileInfo
        For Each aFile In aDir.GetFiles("*.xml")
            Dim sr As StreamReader = New StreamReader(aFile.FullName)
            Dim content As String = sr.ReadToEnd()
            sr.Read()
            Dim strFull As String
            Dim strOriginal As String = "<?xml:stylesheet type="text/xsl" href="../../home.xsl" ?>"
            Dim strReplace As String = ""
            strFull = content.Replace(strOriginal, strReplace)
            MsgBox(strFull)
        Next
    End Sub


But here it's not finding "strOriginal", what needs to be done instead of this?

Thanks,
Shailesh
0
 
LVL 24

Accepted Solution

by:
fridom earned 250 total points
ID: 18887866
Is it really written the mentioned way? I can see at least a few problems:
You write your string with " but within the string you use " also that means it will end the string, so this code cna not compile that way. At least you ahve to quote your " properly.

Regards
Friedrich
0
 
LVL 1

Author Comment

by:ShaileshShinde
ID: 18887868
Yeah..it does not compile it..ask for end of statement..for strOriginal
0
 
LVL 1

Author Comment

by:ShaileshShinde
ID: 18887881
Hello Expert,

I got it i need to put something like this....."<?xml:stylesheet type=""text/xsl"" href=""../../home.xsl"" ?>"

Thanks,
Shailesh
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

730 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