Solved

Removing statements from xml files

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

757 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

18 Experts available now in Live!

Get 1:1 Help Now