C/C++ Source File (XmlLiteReader.cpp)
//-----------------------------------------------------------------------// This file is part of the Windows SDK Code Samples.
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
// This source code is intended only as a supplement to Microsoft
// Development Tools and/or on-line documentation. See these other
// materials for detailed information regarding Microsoft code samples.
//
// THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//-----------------------------------------------------------------------
#include "stdafx.h"
#include <atlbase.h>
#include "xmllite.h"
#include <strsafe.h>
HRESULT WriteAttributes(IXmlReader* pReader)
{
const WCHAR* pwszPrefix;
const WCHAR* pwszLocalName;
const WCHAR* pwszValue;
HRESULT hr = pReader->MoveToFirstAttribute();
if (S_FALSE == hr)
return hr;
if (S_OK != hr)
{
wprintf(L"Error moving to first attribute, error is %08.8lx", hr);
return -1;
}
else
{
while (TRUE)
{
if (!pReader->IsDefault())
{
UINT cwchPrefix;
if (FAILED(hr = pReader->GetPrefix(&pwszPrefix, &cwchPrefix)))
{
wprintf(L"Error getting prefix, error is %08.8lx", hr);
return -1;
}
if (FAILED(hr = pReader->GetLocalName(&pwszLocalName, NULL)))
{
wprintf(L"Error getting local name, error is %08.8lx", hr);
return -1;
}
if (FAILED(hr = pReader->GetValue(&pwszValue, NULL)))
{
wprintf(L"Error getting value, error is %08.8lx", hr);
return -1;
}
if (cwchPrefix > 0)
wprintf(L"Attr: %s:%s=\"%s\" \n", pwszPrefix, pwszLocalName, pwszValue);
else
wprintf(L"Attr: %s=\"%s\" \n", pwszLocalName, pwszValue);
}
if (S_OK != pReader->MoveToNextAttribute())
break;
}
}
return hr;
}
int _tmain(int argc, WCHAR* argv[])
{
HRESULT hr;
CComPtr<IStream> pFileStream;
CComPtr<IXmlReader> pReader;
XmlNodeType nodeType;
const WCHAR* pwszPrefix;
const WCHAR* pwszLocalName;
const WCHAR* pwszValue;
UINT cwchPrefix;
if (argc != 2)
{
wprintf(L"Usage: XmlLiteReader.exe name-of-input-file\n");
return 0;
}
//Open read-only input stream
if (FAILED(hr = SHCreateStreamOnFile(argv[1], STGM_READ, &pFileStream)))
{
wprintf(L"Error creating file reader, error is %08.8lx", hr);
return -1;
}
if (FAILED(hr = CreateXmlReader(__uuidof(IXmlReader), (void**) &pReader, NULL)))
{
wprintf(L"Error creating xml reader, error is %08.8lx", hr);
return -1;
}
if (FAILED(hr = pReader->SetProperty(XmlReaderProperty_DtdProcessing, DtdProcessing_Prohibit)))
{
wprintf(L"Error setting XmlReaderProperty_DtdProcessing, error is %08.8lx", hr);
return -1;
}
if (FAILED(hr = pReader->SetInput(pFileStream)))
{
wprintf(L"Error setting input for reader, error is %08.8lx", hr);
return -1;
}
//read until there are no more nodes
while (S_OK == (hr = pReader->Read(&nodeType)))
{
switch (nodeType)
{
case XmlNodeType_XmlDeclaration:
wprintf(L"XmlDeclaration\n");
if (FAILED(hr = WriteAttributes(pReader)))
{
wprintf(L"Error writing attributes, error is %08.8lx", hr);
return -1;
}
break;
case XmlNodeType_Element:
if (FAILED(hr = pReader->GetPrefix(&pwszPrefix, &cwchPrefix)))
{
wprintf(L"Error getting prefix, error is %08.8lx", hr);
return -1;
}
if (FAILED(hr = pReader->GetLocalName(&pwszLocalName, NULL)))
{
wprintf(L"Error getting local name, error is %08.8lx", hr);
return -1;
}
if (cwchPrefix > 0)
wprintf(L"Element: %s:%s\n", pwszPrefix, pwszLocalName);
else
wprintf(L"Element: %s\n", pwszLocalName);
if (FAILED(hr = WriteAttributes(pReader)))
{
wprintf(L"Error writing attributes, error is %08.8lx", hr);
return -1;
}
if (pReader->IsEmptyElement() )
wprintf(L" (empty)");
break;
case XmlNodeType_EndElement:
if (FAILED(hr = pReader->GetPrefix(&pwszPrefix, &cwchPrefix)))
{
wprintf(L"Error getting prefix, error is %08.8lx", hr);
return -1;
}
if (FAILED(hr = pReader->GetLocalName(&pwszLocalName, NULL)))
{
wprintf(L"Error getting local name, error is %08.8lx", hr);
return -1;
}
if (cwchPrefix > 0)
wprintf(L"End Element: %s:%s\n", pwszPrefix, pwszLocalName);
else
wprintf(L"End Element: %s\n", pwszLocalName);
break;
case XmlNodeType_Text:
case XmlNodeType_Whitespace:
if (FAILED(hr = pReader->GetValue(&pwszValue, NULL)))
{
wprintf(L"Error getting value, error is %08.8lx", hr);
return -1;
}
wprintf(L"Text: >%s<\n", pwszValue);
break;
case XmlNodeType_CDATA:
if (FAILED(hr = pReader->GetValue(&pwszValue, NULL)))
{
wprintf(L"Error getting value, error is %08.8lx", hr);
return -1;
}
wprintf(L"CDATA: %s\n", pwszValue);
break;
case XmlNodeType_ProcessingInstruction:
if (FAILED(hr = pReader->GetLocalName(&pwszLocalName, NULL)))
{
wprintf(L"Error getting name, error is %08.8lx", hr);
return -1;
}
if (FAILED(hr = pReader->GetValue(&pwszValue, NULL)))
{
wprintf(L"Error getting value, error is %08.8lx", hr);
return -1;
}
wprintf(L"Processing Instruction name:%S value:%S\n", pwszLocalName, pwszValue);
break;
case XmlNodeType_Comment:
if (FAILED(hr = pReader->GetValue(&pwszValue, NULL)))
{
wprintf(L"Error getting value, error is %08.8lx", hr);
return -1;
}
wprintf(L"Comment: %s\n", pwszValue);
break;
case XmlNodeType_DocumentType:
wprintf(L"DOCTYPE is not printed\n");
break;
}
}
return 0;
}
XML Source File (stocks.xml)
<?xml version="1.0"?><portfolio xmlns:dt="urn:schemas-microsoft-com:datatypes">
<stock exchange="nasdaq">
<name>new</name>
<symbol>zzzz</symbol>
<price>20.313</price>
</stock>
<stock exchange="nyse">
<name>zacx corp</name>
<symbol>ZCXM</symbol>
<price>28.875</price>
</stock>
<stock exchange="nasdaq">
<name>zaffymat inc</name>
<symbol>ZFFX</symbol>
<price>92.250</price>
</stock>
<stock exchange="nasdaq">
<name>zysmergy inc</name>
<symbol>ZYSZ</symbol>
<price>20.313</price>
</stock>
</portfolio>
Output from XmlLiteReaderXmlDeclaration
Attr: version="1.0"
Text: >
<
Element: portfolio
Attr: xmlns:dt="urn:schemas-microsoft-com:datatypes"
Text: >
<
Element: stock
Attr: exchange="nasdaq"
Text: >
<
Element: name
Text: >new<
End Element: name
Text: >
<
Element: symbol
Text: >zzzz<
End Element: symbol
Text: >
<
Element: price
Text: >20.313<
End Element: price
Text: >
<
End Element: stock
Text: >
<
Element: stock
Attr: exchange="nyse"
Text: >
<
Element: name
Text: >zacx corp<
End Element: name
Text: >
<
Element: symbol
Text: >ZCXM<
End Element: symbol
Text: >
<
Element: price
Text: >28.875<
End Element: price
Text: >
<
End Element: stock
Text: >
<
Element: stock
Attr: exchange="nasdaq"
Text: >
<
Element: name
Text: >zaffymat inc<
End Element: name
Text: >
<
Element: symbol
Text: >ZFFX<
End Element: symbol
Text: >
<
Element: price
Text: >92.250<
End Element: price
Text: >
<
End Element: stock
Text: >
<
Element: stock
Attr: exchange="nasdaq"
Text: >
<
Element: name
Text: >zysmergy inc<
End Element: name
Text: >
<
Element: symbol
Text: >ZYSZ<
End Element: symbol
Text: >
<
Element: price
Text: >20.313<
End Element: price
Text: >
<
End Element: stock
Text: >
<
End Element: portfolio
To create the example
-
Create a Visual Studio 2005 project. For details of how to do this, see Building XmlLite Applications.
-
Copy the content of Source: XmlLiteReader.cpp into your C++ source file.
-
Build the example. Building the example will also create the debug directory, which is required for the next step.
-
Copy the sample XML file to the clipboard, and paste it into your favorite editor to create an XML document. Place the document in the debug directory.
-
Run the sample and verify that the output matches the output provided.
These are actually fantastic ideas in about blogging.
ReplyDeleteYou have touched some fastidious points here. Any way keep up wrinting.
Feel free to surf to my homepage ... Nuvocleanse Diet
Good information. Lucky me I discovered your blog by accident (stumbleupon).
ReplyDeleteI have saved it for later!
Also visit my website Androsolve
I am now not certain the place you're getting your information, however great topic. I needs to spend a while learning more or working out more. Thanks for wonderful information I used to be in search of this information for my mission.
ReplyDeleteHere is my web-site; Pure Garcinia Cambogia
Hello! This is kind of off topic but I need some guidance from an
ReplyDeleteestablished blog. Is it difficult to set up your own blog?
I'm not very techincal but I can figure things out pretty fast. I'm thinking
about setting up my own but I'm not sure where to begin. Do you have any tips or suggestions? Appreciate it
Here is my webpage - Elevate GF And 1285 Muscle
This website was... how do I say it? Relevant!
ReplyDelete! Finally I have found something which helped me.
Kudos!
Also visit my web-site: Liposom reviews
First of all I want to say terrific blog! I had a quick
ReplyDeletequestion that I'd like to ask if you do not mind. I was interested to find out how you center yourself and clear your mind prior to writing. I've had a
difficult time clearing my thoughts in getting my
ideas out. I do enjoy writing however it just seems like the first 10
to 15 minutes are lost simply just trying to figure out how to begin.
Any suggestions or hints? Cheers!
Here is my web blog :: Nuvocleanse
Write more, thats all I have to say. Literally, it seems as though you relied on
ReplyDeletethe video to make your point. You obviously know what
youre talking about, why throw away your intelligence on just posting
videos to your weblog when you could be giving us something informative to read?
My website ... acai ultra lean
It's very trouble-free to find out any matter on net as compared to books, as I found this article at this website.
ReplyDeleteFeel free to surf to my webpage ... Rejuvenex review
Hi there this is somewhat of off topic but I was wondering
ReplyDeleteif blogs use WYSIWYG editors or if you have to manually code with HTML.
I'm starting a blog soon but have no coding expertise so I wanted to get guidance from someone with experience. Any help would be enormously appreciated!
Also visit my website ... Green coffee review
Aw, this was an extremely nice post. Spending some time
ReplyDeleteand actual effort to generate a great article… but what can
I say… I procrastinate a lot and never manage to get nearly anything done.
Feel free to surf to my blog: Cambogia trim review
always i used to read smaller articles or reviews which also clear their motive,
ReplyDeleteand that is also happening with this post which I am reading here.
Look into my weblog; Order Raspberry Ketone Plus
Its not my first time to go to see this site, i am browsing this web page dailly and obtain good information from here all the time.
ReplyDeleteMy web site: Pay day loans
you're actually a excellent webmaster. The website loading velocity is amazing. It sort of feels that you are doing any unique trick. In addition, The contents are masterpiece. you've performed a
ReplyDeletewonderful task on this matter!
My webpage; TruVisage Review
Every weekend i used to visit this web site, for the reason that i wish
ReplyDeletefor enjoyment, for the reason that this this web site conations really
nice funny stuff too.
Also visit my webpage; Vimax Review
I am in fact thankful to the owner of this web site who has shared
ReplyDeletethis wonderful paragraph at here.
Review my weblog; Slim Helper Weight Loss Patch
Very good article. I will be experiencing some of these issues as well.
ReplyDelete.
Here is my webpage: Skin cream
Valuable information. Lucky me I found your site by accident, and I am stunned why
ReplyDeletethis twist of fate didn't happened earlier! I bookmarked it.
Visit my web page - uy Le derme luxe
Hey very interesting blog!
ReplyDeleteHere is my blog; Swiss rose reviews
Excellent web site you've got here.. It's hard to find high quality writing like yours these days.
ReplyDeleteI really appreciate individuals like you! Take care!!
Also visit my blog; Lean muscle x and test force xtreme
Hey! Do you know if they make any plugins to safeguard
ReplyDeleteagainst hackers? I'm kinda paranoid about losing everything I've worked
hard on. Any tips?
Here is my homepage - Pro Collagen Cream
Thank you for the auspicious writeup. It in fact used to be a enjoyment
ReplyDeleteaccount it. Glance complicated to more delivered agreeable from you!
By the way, how could we keep in touch?
my page; internet money making
Very great post. I simply stumbled upon your weblog and wished to
ReplyDeletemention that I have really enjoyed surfing around your blog posts.
In any case I will be subscribing for your feed and I'm hoping you write again soon!
My web page :: Rvtl Eye creams
Hello everybody, here every one is sharing these experience, thus it's pleasant to read this weblog, and I used to go to see this website daily.
ReplyDeleteMy web blog: Build muscle now
Great blog you have got here.. It's difficult to find high-quality writing like yours these days. I really appreciate individuals like you! Take care!!
ReplyDeleteHave a look at my web page :: Best Wrinkle Creams
My brother recommended I might like this website.
ReplyDeleteHe was totally right. This post truly made my day. You cann't imagine simply how much time I had spent for this info! Thanks!
my web-site :: garcinia cambogia
Hello, its nice paragraph concerning media print, we all know media is a impressive source of information.
ReplyDeletemy web blog: Fase cream
Hey there! Quick question that's entirely off topic. Do you know how to make your site mobile friendly? My web site looks weird when viewing from my iphone. I'm trying to find a template
ReplyDeleteor plugin that might be able to correct this issue.
If you have any recommendations, please share.
Many thanks!
My web-site Diet Patch Trial
I blog frequently and I genuinely appreciate your
ReplyDeleteinformation. The article has really peaked my interest.
I am going to take a note of your site and keep checking for
new information about once a week. I subscribed to your
RSS feed as well.
Also visit my blog: Collagen
Just wish to say your article is as astonishing. The clarity in
ReplyDeleteyour post is simply excellent and i can assume you are an expert on this subject.
Well with your permission allow me to grab your feed to keep up
to date with forthcoming post. Thanks a million and please carry on the
enjoyable work.
Have a look at my weblog Androsolve Testosterone Booster
If you wish for to increase your know-how simply keep visiting this web site and be
ReplyDeleteupdated with the newest information posted here.
Feel free to visit my web-site: Slim Helper Weight Loss Patch
Good article! We will be linking to this particularly
ReplyDeletegreat content on our website. Keep up the great writing.
Feel free to visit my web site: Buy 1285 muscle
Fastidious answer back in return of this question with genuine arguments and describing
ReplyDeletethe whole thing about that.
Take a look at my web page Buy garciniacambogia
Hey there! Do you use Twitter? I'd like to follow you if that would be ok. I'm definitely enjoying
ReplyDeleteyour blog and look forward to new posts.
Feel free to surf to my blog post; how to get money fast
Wow that was unusual. I just wrote an extremely long comment but after
ReplyDeleteI clicked submit my comment didn't appear. Grrrr... well I'm not writing all that
over again. Anyhow, just wanted to say fantastic blog!
Look at my web blog ... Anatomy X5 Reviews
I was curious if you ever thought of changing the structure
ReplyDeleteof your website? Its very well written; I love what youve got to say.
But maybe you could a little more in the way of content so people could connect with it better.
Youve got an awful lot of text for only having 1 or 2 images.
Maybe you could space it out better?
my web page; Green coffee
If you want to take a great deal from this post then you have to apply
ReplyDeletethese techniques to your won weblog.
Also visit my page: muscle supplements
This is a topic that's close to my heart... Thank you! Where are your contact details though?
ReplyDeleteHere is my web page Ripped XL Supplements
Simply desire to say your article is as astounding.
ReplyDeleteThe clarity in your post is just excellent and i can assume you are
an expert on this subject. Fine with your permission allow
me to grab your RSS feed to keep up to date with forthcoming post.
Thanks a million and please carry on the rewarding work.
Also visit my web-site; Home Staging Minnesota
Thanks for some other informative site. The place else may I get that kind of information written in such an
ReplyDeleteideal method? I have a project that I'm simply now running on, and I have been at the glance out for such info.
my homepage: puregarciniacambogianow.com
Admiring the persistence you put into your website and detailed information
ReplyDeleteyou provide. It's good to come across a blog every once in a while that isn't the same old rehashed material.
Wonderful read! I've saved your site and I'm adding your RSS feeds to
my Google account.
my web page: Ripped Muscle X treme
I have read so many content about the blogger lovers but this article is really a good post, keep it up.
ReplyDeleteCorporate Movers
hello!,I really like your writing very so much! proportion we keep in touch more about your post on AOL?
ReplyDeleteI require an expert in this area to resolve my problem. Maybe
that's you! Looking forward to see you.
My web blog - weight loss
This post is actually a pleasant one it assists new the web viewers, who are wishing for blogging.
ReplyDeleteAlso visit my blog ... Androsolve Muscle Builder
Hi there everyone, it's my first pay a quick visit at this web site, and article is actually fruitful for me, keep up posting these types of articles or reviews.
ReplyDeletebuy testostrong
Wow that was odd. I just wrote an incredibly long comment but
ReplyDeleteafter I clicked submit my comment didn't show up. Grrrr... well I'm not writing
all that over again. Anyways, just wanted to
say superb blog!
my site; Green coffee
Terrific work! This is the kind of information that are supposed to be shared around the internet.
ReplyDeleteDisgrace on the seek engines for now not positioning
this put up upper! Come on over and consult with my web site
. Thank you =)
profit master
Hi, after reading this amazing article i am also
ReplyDeleteglad to share my knowledge here with mates.
muscle building
Its like you read my mind! You appear to grasp so much about this, like you wrote the e-book in it or something.
ReplyDeleteI think that you simply can do with some p.c. to pressure
the message house a little bit, however instead of that,
this is excellent blog. An excellent read.
I will definitely be back.
buy Ultra Force
Very good article! We are linking to this particularly great article on our website.
ReplyDeleteKeep up the good writing.
Also visit my page: Cambogia trim review
You could definitely see your skills within the work you write.
ReplyDeleteThe sector hopes for even more passionate writers such as you who aren't afraid to mention how they believe. At all times follow your heart.
My blog - green coffee bean
I've been browsing online more than 3 hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. In my opinion, if all webmasters and bloggers made good content as you did, the web will be a lot more useful than ever before.
ReplyDeletemy web-site :: Author's external home page.
..
Whats up very cool site!! Guy .. Excellent .. Wonderful ..
ReplyDeleteI will bookmark your site and take the feeds additionally?
I'm glad to find a lot of helpful information right here within the publish, we need work out extra strategies in this regard, thanks for sharing. . . . . .
Here is my homepage ... lean muscle