|
-
Apr 12th, 2011, 02:19 AM
#1
Thread Starter
Lively Member
removing a line from xml file created thr' code
a xml file is created thr' code using vb6.0 & parsed for validation using sax parser
when paarsing due to line formating
<?xml version="1.0" encoding="utf-8" standalone="yes" ?> gets appended to the existing data at the start of the file ie the first line
is there any way that it culd be deleted programatically
i tried thi smethod
Dim xmldom1 As MSXML2.DOMDocument40
xmldom1.Load FileName
Dim toRemove As String
toRemove = "UTF-16"
Set nodeTemp = xmldom1.selectSingleNode("xml version/encoding[@standalone = '" + toRemove + "']")
nodeInvoiceItems.parentNode.removeChild (nodeTemp)
but nothing dne
Last edited by svibuk; Apr 13th, 2011 at 02:02 AM.
-
Apr 13th, 2011, 03:03 AM
#2
Re: removing a line from xml file created thr' code
It is considered very bad form to resurrect a dead thread. The other thread you posted to was 6 years old, and the principals may be dead themselves by now.
You probably haven't had any replies here because you have not made the problem clear.
You say "xml file" but do you really mean you have a disk file of XML in this form, or are you really saying you are creating an XML file and want to create it without the processing instruction (XML declaration here)?
How to create the XML file right in the first place is very different from creating the file, then reading it back stripping the processing instruction and writing out a second file... if you have a file at all, and not XML in a String in memory or something.
You say "a xml file is created thr' code using vb6.0" which obviously is not true or else you'd just delete the code that wrote the processing instruction to disk. It is much more lkely you are populating an MSXML DOMDocument in a VB6 program and then using its .save method or something.
If that were true though the answer should be just as simple. The DOMDocument doesn't create this processing instruction by default as far as I know.
The MXXMLWriter object has an .omitXMLDeclaration property you can set False if that's what you are using to create the resulting validated XML.
Clarity is very important. Sometimes posting a small example demonstrating the problem helps a great deal.
-
Apr 13th, 2011, 04:33 AM
#3
Thread Starter
Lively Member
Re: removing a line from xml file created thr' code
sorry for the confusion
let me explain u the things from start
in my vb code i have a sql query which retrive data from database &
from this records fetched the xml document gets created (saved)
the code after fetching records ia as follows
Set doc = CreateObject("MSXML2.DOMDocument.4.0")
xmldoc.loadXML "<SALESROOT />"
Set nodeRoot =doc.documentElement
nodeRoot.setAttribute "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"
nodeRoot.setAttribute "xsi:noNamespaceSchemaLocation", "val.xsd"
Set nodeHeadData = doc.createElement(UCase("Header"))
nodeLetter.appendChild nodeHeadData
Set nodetemp = doc.createElement(UCase("Year"))
nodetemp.nodeTypedValue = Trim(RS1.Fields("Year").Value)
nodeHeadData.appendChild nodetemp
Set nodetemp = doc.createElement(UCase("Q"))
nodetemp.nodeTypedValue = Trim(RS1.Fields("Q").Value)
nodeHeadData.appendChild nodetemp
Set nodetemp = doc.createElement(UCase("Name"))
nodetemp.nodeTypedValue = Trim(RS1.Fields("Name").Value)
nodeHeadData.appendChild nodetemp
doc.save "test.xml"
this is wht i was getting initally
then i added the parsing for validation which i had told u
but after parsing as i was not getting the exact location error location so started the thread
after u gave the Formatdoctofile function
i started getting that first line <?xml version..................
i hope i am clear abt savng teh file or creating the file
this is how i am getting now
<?xml version="1.0" encoding="UTF-16" standalone="no" ?> ----- not needed
- <SALESROOT xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="val.xsd">
Last edited by svibuk; Apr 13th, 2011 at 04:43 AM.
-
Apr 13th, 2011, 04:48 AM
#4
Re: removing a line from xml file created thr' code
Ok, so why not set the property to True?
Code:
Private Sub FormatDocToFile(ByVal Doc As MSXML2.DOMDocument, ByVal FileName As String)
'Reformats the DOMDocument "Doc" into an ADODB.Stream and writes it to
'the specified file.
'
'Note the UTF-8 output never gets a BOM. If we want one we have to write it
'here explicitly after opening the Stream.
Dim wtrFormatted As MSXML2.MXXMLWriter
Dim stmFormatted As ADODB.Stream
Dim rdrFormatted As MSXML2.SAXXMLReader
Set wtrFormatted = New MSXML2.MXXMLWriter
With wtrFormatted
.omitXMLDeclaration = False '<----<< True to omit it.
.standalone = True
.byteOrderMark = False 'If not set then .encoding is ignored.
.encoding = "utf-8" 'Even if .byteOrderMark = True UTF-8 never gets a BOM.
.indent = True
Set stmFormatted = New ADODB.Stream
With stmFormatted
.Open
.Type = adTypeBinary
End With
.output = stmFormatted
Set rdrFormatted = New MSXML2.SAXXMLReader
With rdrFormatted
Set .contentHandler = wtrFormatted
Set .dtdHandler = wtrFormatted
Set .errorHandler = wtrFormatted
.putProperty "http://xml.org/sax/properties/lexical-handler", wtrFormatted
.putProperty "http://xml.org/sax/properties/declaration-handler", wtrFormatted
.parse Doc
End With
With stmFormatted
.SaveToFile FileName
.Close
End With
End With
End Sub
-
Apr 13th, 2011, 04:56 AM
#5
Thread Starter
Lively Member
Re: removing a line from xml file created thr' code
ok thanks
by making it true i was able to remove the line
i am sorry for any confusion if created
now i got back my normal xml fle
just for info i wanted to knw
that the code i have is knwon as creating a xml file or just saving it
secondaly is there any way to highlight the error line or data after parsing as the browser doesnot show any line nos(if possibe)
-
Apr 13th, 2011, 05:46 AM
#6
Re: removing a line from xml file created thr' code
Where does a browser come into the picture? Are you opening the XML file on disk in a browser?
You might be better off using a text editor with line numbers or something. Maybe NotePad++, which is popular and there is even an XML Tools plug-in for it.
-
Apr 13th, 2011, 06:13 AM
#7
Thread Starter
Lively Member
Re: removing a line from xml file created thr' code
ya the users open the xml in browsers
ya i hve done with notepad++
its very easy to detect lin eno
but if the error line or data is highlighted when viewed in browser
it wuld be more efficient way as otherwise the user needs to copy the xml generated in the editor & check for the error line
if its possible by any way else need to opt for notepad++
-
Apr 13th, 2011, 06:21 AM
#8
Re: removing a line from xml file created thr' code
Why would a user ever be looking at XML? It really isn't the kind of thing users should ever see. Why are they looking at it?
I'm not sure I can help. If the users need to edit and validate XML they should be using appropriate tools. If you are trying to make such a tool for them you need to do more work about displaying it than dumping it into a browser.
-
Apr 13th, 2011, 06:31 AM
#9
Thread Starter
Lively Member
Re: removing a line from xml file created thr' code
ok, the reason that the user cant open in the editor is that they are not allowed any elements modification ,
they just need to modify the data in case if its invalid and that too in the database connected to a entry form
no editing is allowed to make in the xml directly
as i told i get the data from database , the user can modify the data only thr' the database form
so opened in browser
after the data of the application is modified they need to recreate the xml as this data is reflected in some other places aslo
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|