|
There is a 'whitespace' element in the DOM, I've never used it since it costs performance to use.
see http://www.xml.com/pub/a/2001/12/05/whitespace.html
|
|
|
|
|
Allright, I may be completely off track here - but the link you refer to deals with the problems of showing the data from the XML file using a stylesheet, and getting line breaks in the resulting "view".
What I want, is linebreaks in my XML file. When I generate this data structure :
<parent>
<child>
<data1>bla</data1>
<data2>bla</data2>
</child>
</parent>
from VC++, the _file_ looks like this :
<parent><child><data1>bla</data1><data2>bla</data2></child></parent>
- which, of course, is correct - but not what I want.
What do you think ? completely off track and unable to understand the link you gave me ;o) ?
Thanks anyway.
/Jan
|
|
|
|
|
there is property of xmlwriter than creates/preserves space.
personally I allways turn it off.
|
|
|
|
|
whoops, yea, posted wrong link! My bad.
You definately are looking for the whitespace setting. I cant find the link I was going to give you now, though.
|
|
|
|
|
The problem you are facing is true if you read the xml in a text editor. But any xml editor should automatically reorganize the display of your data in the "neat" way. I am assuming this is your objective. Unless you wish to read it in a simple text editor and yet have it formatted. In which case.... hmmmm... too much effort, when there are so manty xml editors and tools available. Including IE which will display your XML in the "neat" way.
|
|
|
|
|
I want to use XML to transport some data across HTTP protocol. When text in some element contains US ASCI characters then all is OK. But when some language- specific characters appear i get error.
I want to encode contents of some elements (these that contain these unfortunate characters) to BASE.64.
when I do the following, I get error.
_variant_t var_val=GetSomeText_WithStrangeChars()
..check errorcodes...
pNewNodeOut->put_dataType(L"bin.base64");
..check errorcodes... //ok it works so far
pNewNodeOut->put_nodeTypedValue(var_val); //HERE CRASH
//It is here where HRESULT is E_FAIL
The first question is: What to do to avoid error, and
to sucessfully put value of _variant_t (containing BSTR)
into element whose type is set to bin.base64 ?
The last question is:
Shall I be able to automatically get the value of the
element without explicit converting it from BASE.64 ?
I mean : Shall MSXML parser do the conversion automatically for me when I will call nodeTypedValue property ?
Thanks
Michal Januszczyk
|
|
|
|
|
|
I am doing the folowing operations:
1. Export some tables (that have unique IDs and foreign keys) to an XML file using a DataSet object in .NET. This works file.
2. I want to be able to import that XML file into another SQLServer server that has the same database architecture, but of course, different data.
3. When reading the XML file into a Dataset and then updating the database, some key violations or duplicate records may occur because I exported some unique IDs from one databse server and am trying to import them into another server. Thus, when importing a master table, I must read the XML file and give the corresponding records new IDs accordingly. Since my master table will have several slave tables with foreign keys involved I would have to udpate the slave tables also to maintain the integrity.
I could do all that manually by having lots of structures and maps and hash tables. Is there a change .NET Dataset would take care of everything automatically for me?
Thanks.
Best regards,
Alexandru Savescu
|
|
|
|
|
Hello guys,
I am about to self-teach myself some XML stuff. Till now, what I have seen in the MSDN mixed me up a little bit.
It seems that to do anything interesting with MS Explorer and XML, you will have to use a lot scripting.
I am not very interested in scripting (even though I know how to script in vbscript and jscript).
Is scripting always necessary to use when using XML in IE? Or could a good combination of XML and HTML do the trick?
Jeremy.
"Hey man, Taliban, Tali me Banana."
|
|
|
|
|
no
Xml has its own transform language, XSL, which can be used to do very interesting things. It can transform XML in one format to another format (for example <player name="tom"/> to <player>tom</player>)
You can also use this to output HTML, raw text, CSS, ASP scripts, source code, and more. For example, I have an XSL file i built which transforms Winamp 3 playlists to M3U playlists very quickly. I have another which presents the playlist as an HTML page for viewing.
If another media player used XML for playlists but had a totally different node structure, I could port my playlist from Winamp to that program by simply writing a quick XSL doc.
Or if i wanted to write a program in C++ with all my music files as constant strings (for performance ), I could write an XSL doc to quickly transform it into a compilable .CPP file.
There is a lot more, but thats a good start loc.
|
|
|
|
|
Christopher,
I'm looking to do a conversion from Windows Media playlists (.asx, etc.), which is in an xml format, to Winamp .pls for use in the Turtle Beach AudioTron file player I just bought (extremely cool gizmo, by the way).
I haven't done anything with xml/xsl yet, but your description of the xsl transform language sounds perfect. Could you point me to some documentation on this feature? I'm not looking to really learn xml in full just yet, I merely have a single problem I need to solve as simply & quickly as I can make it.
Thanks!
Chistopher Duncan
Author - The Career Programmer: Guerilla Tactics for an Imperfect World (Apress)
|
|
|
|
|
XSL is mainly for changing XML dialects (XHTML included).
In order to transform to non-xml files, like M3U or TXT, you have to either craft your transform very carefully (many formats will not work because they may use tags which conflict) or use something like FOP (http://xml.apache.org/fop/index.html)
You'll also have to watch out for whitespace, since most plain-text formats are very picky. Many xsl engines let you use absolute whitespace.
|
|
|
|
|
|
Scripting is necessary if you want to use the DOM to process XML. If you don't want to do that, you can use XSLT.
XSLT is pretty cool, but it is quite challenging to master. You can take a look at 2 XSLT articles I wrote (while I was still using the name MarSCoZa).
|
|
|
|
|
One option is to use th DSO (Data Source Object) and a tiny bit of scripting (2-3 lines) to bind a control like a lisst box to an XML data source. Other than that, you can combine your XML with XSL to get IE to render an HTML-like document.
Erik Westermann
Author, Learn XML In A Weekend (Summer 2002)
|
|
|
|
|
Definitely do some reading at TopXML
|
|
|
|
|
Check out an article about CMarkupArchive by Jonathan de Halleux.
I use it in my apps.
|
|
|
|
|
Hi,
I've just got started with XML and VC6.0 (thanks to Tom Archer : http://codeguru.earthweb.com/xml/XMLDOMFromVC.html - great explanation/tutorial !!!) and I'm wondering how I can write data back to an XML file. I use the DOM as described in the article to read data from a file to internal datastructures - but I need to update different values in my XML file after updating the datastructures. How is this done most easily ? Currently, I see two ways of doing it : writing the XML file as ascii based on the data or using the DOM to generate a file. The first I can do ;o) - but how is the latter done ? And is that the "right" way to do it ?
Thanks in advance.
Best regards
Jan Hansen
|
|
|
|
|
u have seem to have solved the question about retrieving data.
XML DOM supports for Data insertion . Additionally it is advantageous as you will follow a syntax to add data . In case the DOM object could not add data it will notify . I think that using the DOM to insert Data is the way to go about this .
Also try exploring SAX .
|
|
|
|
|
Use the DOM. To set the value of an element use the same method you used to get the text, but instead set it.
Finally call the save method of the DOMDocument to save your DOM as an XML file.
Drinking In The Sun
Forgot Password?
|
|
|
|
|
You can use DOM to both modify data ( change values of existing nodes) and to modify the structure of your XML (Add or remove nodes).
DOMDocument has functions like CreatNode, CreateElement etc. Once you create a Node you can insert it or append it to an existing to node in your XML. Think of it as dealing with a tree structure.
Changing the value is easier. You just set the new value.
For example node.firstChild.Attributes.getNamedItem("blah").Text = "Yoooo Hoooo"
This will find an attribute named blah in your node and set its text to "Yoooo Hoooo"
You can try doing this yourself by editing the text but that would be reinventing the wheel.
Hope this helped. You may want to look into MSDN for more precise syntax and examples.
|
|
|
|
|
Thanks a lot !
I have looked (a little) at the "root-object", and there doesn't seem to be a "flush-to-disk" operation. During the lifetime of my application, I would like to ensure that changes to the data in the file are written - just to prevent a crash of the framework I'm working inside from deleting changes. Any idea how this is done ? Or do I have to sort of close the document?
/Jan
|
|
|
|
|
You need to look up help/documention for DOMDocument. It has a funtion called save that will save your XML. DOMDocument is where you load your XML. Then you use the nodes to manipulate the content. Then you save the DOMDocument.
|
|
|
|
|
Hi all, and thanks a lot for the help so far.
I now read data, delete some data from my XML tree ,and insert some data. Then I save the data to the file I loaded it from. Everything works fine - except for the formatting. I tend to format my XML data C-like, with tabular indents etc. This is kept in the part of the XML tree not modified from C++ - but the data added from C++ is written in one long line like this
<parent><child1>blah<child2>blah
- any way I can ask the XML engine to format things "my way" or a "standard way". By the way, the data not modified from C++ is getting (damn, whats the word...) truncated/fitted/"replace-one-or-more-newlines-with-only-one-newline". But tabs are kept.
Any hints, oh allmighty gurus of knowledge ;o)
Thanks in advance
/Jan
|
|
|
|
|