Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am Using MSXML Parser with vc++ to parse a xml file to construct a tree control and the back to another xml file.Everything is fine,but the indention in the xml file created through MSXML is not good. All the nodes are created in a single line.How to indent them?

Regards,
venkatanaraytana

There is an indent property that you can set to true (assuming you are writing one of the writer classes in the library).

[Update]
~~~~~~~~~~~~~

See http://msdn.microsoft.com/en-us/library/ms764689(v=vs.85).aspx[^]
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 8-Feb-11 16:44pm    
Simple as that. 5.
--SA
Nish Nishant 8-Feb-11 18:41pm    
Thank you.
Thanks nishant,I got the solution with your clue,The solution is,
FormatDOMDocument(MSXML2::IXMLDOMDocumentPtr pDoc, CString& omstrFilePath)
{
MSXML2::ISAXXMLReaderPtr pReader = NULL;

pReader.CreateInstance(L"Msxml2.SAXXMLReader.4.0");


CComPtr<istream> pStream;
DWORD grfMode = STGM_WRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE;

HRESULT hav=SHCreateStreamOnFile ((LPCTSTR)omstrFilePath, grfMode, &pStream);

MSXML2::IMXWriterPtr w;

w.CreateInstance (L"Msxml2.MXXMLWriter.4.0");
w->put_output (CComVariant(pStream));

pReader->putContentHandler((MSXML2::ISAXContentHandlerPtr)wtr);
pReader->putErrorHandler((MSXML2::ISAXErrorHandlerPtr)wtr);
pReader->putDTDHandler((MSXML2::ISAXDTDHandlerPtr)wtr);

w->put_byteOrderMark(VARIANT_TRUE);
w->put_indent(VARIANT_TRUE);

HRESULT hr = pReader->parse((_variant_t)(pDoc.GetInterfacePtr()));

w->flush ();
return true;
}
Nish Nishant 12-Feb-11 14:01pm    
You are welcome.
we're using a stylesheet transform to "pretty" format the outgoing XML.

see this thread on stackoverflow :
StackOverflow[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 8-Feb-11 16:45pm    
Nah! - overkill. See Answer by Nishant.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900