Solved

Removing statements from xml files

Posted on 2007-04-10
5
149 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now