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
Solved

Removing statements from xml files

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

860 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