473,698 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlWriter - can't figure out how to create this element

**Disclaimer** The element I need to create might not be valid XML, but
it's not my fault, I'm following a required format for an integration
project.

I've got 99% of the XML created nicely using XmlWriter, there is one line
that I can't figure out how to generate:
<ServicesCertif iedMail="OFF" DeliveryConfirm ation="ON" ></Services>

I've tried several different combinations of methods and can't seem to
generate that string. Is it possible? If so, anyone know what I need to
do? I tried calling WriteString but it replaced the "<>" characters with
something else.

Thanks for reading,
Steve
Jun 10 '07 #1
12 1557
Have you tried WriteRaw()?

Marc

Jun 10 '07 #2
sklett <s@s.comwrote :
**Disclaimer** The element I need to create might not be valid XML, but
it's not my fault, I'm following a required format for an integration
project.
Well, it's definitely not XML, and won't be able to be parsed by any
XML parser.

If you need to write non-XML, I suggest you use something other than an
XmlWriter - while stressing to management (or whoever) that it's a
pretty horrible file format.

One alternative would be to write "real" XML and then a second process
which took the real XML and generated the required pseudo-XML. That way
you could still use real XML for most of the processing, which may well
make things easier.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 10 '07 #3
Hi Narc,

I somehow missed WriteRaw() last night, thanks for the suggestion! I just
tried it and it does write out the exact string I've given it, but with a
strange side effect: All subsequent calls to WriteElementStr ing are being
placed on the same line, one after another.
Here is an example:
<PackageType>RE CTPARCEL</PackageType>
<WeightOz>1.7 </WeightOz>
<Width>10</Width>
<Length>10</Length>
<Depth>10</Depth>
<ServicesCertif iedMail="OFF" DeliveryConfirm ation="ON" ></Services>
<Value>0.00</Value><Descript ion>Sales Order#
531</Description><Re ferenceID>531</ReferenceID>
After the lined starting with "<Services. .." everything is getting throw on
the same line. I tried resetting the formating but that didn't make any
difference. Here is the code that seems to be causing the problem:
<code>
writer.WriteEle mentString("Pac kageType", "RECTPARCEL ");
writer.WriteEle mentString("Wei ghtOz", package.Weight. ToString());
writer.WriteEle mentString("Wid th", "10");
writer.WriteEle mentString("Len gth", "10");
writer.WriteEle mentString("Dep th", "10");

// <ServicesCertif iedMail="OFF" DeliveryConfirm ation="ON" ></Services>
// This is a non-standard element (I think) so I'm just dumping the string
literal into the file
writer.WriteRaw (Environment.Ne wLine);
writer.WriteRaw ("<ServicesCert ifiedMail=\"OFF \" DeliveryConfirm ation=\"ON\"
></Services>");
writer.WriteRaw (Environment.Ne wLine);
writer.Formatti ng = Formatting.Inde nted;

writer.WriteEle mentString("Val ue", "0.00");
writer.WriteEle mentString("Des cription", package.Referen ceLine1);
writer.WriteEle mentString("Ref erenceID",
fulfillment.Sal esOrder.Transac tionNumber);
</code>

Do you see anything there that would cause the writer to not write line
breaks after the call to WriteRaw()?

Thanks for any ideas,
Steve

"Marc Gravell" <ma**********@g mail.comwrote in message
news:11******** **************@ r19g2000prf.goo glegroups.com.. .
Have you tried WriteRaw()?

Marc

Jun 10 '07 #4
Thanks for the ideas and suggestions Jon.
I have been making noise to the api developers for this specific tool....
they just don't care.
I'm real close to having a working solution, just need to sort out a newline
issue (posted in previous message).

Thanks again for the suggestions,
Steve

"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************@m snews.microsoft .com...
sklett <s@s.comwrote :
>**Disclaimer ** The element I need to create might not be valid XML, but
it's not my fault, I'm following a required format for an integration
project.

Well, it's definitely not XML, and won't be able to be parsed by any
XML parser.

If you need to write non-XML, I suggest you use something other than an
XmlWriter - while stressing to management (or whoever) that it's a
pretty horrible file format.

One alternative would be to write "real" XML and then a second process
which took the real XML and generated the required pseudo-XML. That way
you could still use real XML for most of the processing, which may well
make things easier.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jun 10 '07 #5
From what I've observed, your XML is poorly formed and lacks consistent
structural style. You are using both elements and attributes which I concede
may be neccessary but in general just as often can and probably should be
restructured.

Secondly, the following use of an attribute as an element name is the
poorest type of form I have ever observed:

<ServicesCertif iedMail="OFF" DeliveryConfirm ation="ON" ></Services>

To solve the problem you are talking about -- in this news article -- simply
refine your form:

<CertifiedMailS ervices serviceState="o ff" deliveryConfirm ation="on" />

Some time ago I wrote a similar RFI regarding style, form, and in particular
naming conventions was answered by Oleg Tkachenko an XML MVP [1]. I found
his reply useless as it obviates common sense.

The format I wrote above is what I have adopted ehich follows Tkachenko's
sage comments; the format being consistent with my use of C#. Further, what
I suggest one learn from this form of styling is the fact that the XmlWriter
will write attributes easily and as expected when the base form is in fact
well-formed and consistent of the ideal of that state of being well-formed,
i.e. when we clean up our sloppy form many of our problems go away. So I'm
trying to tell ya'...

Get some style boy ;-)

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee. com
URL http://clintongallagher.metromilwaukee.com/

[1] http://www.thescripts.com/forum/thread178080.html

"sklett" <s@s.comwrote in message
news:e0******** ******@TK2MSFTN GP03.phx.gbl...
**Disclaimer** The element I need to create might not be valid XML, but
it's not my fault, I'm following a required format for an integration
project.

I've got 99% of the XML created nicely using XmlWriter, there is one line
that I can't figure out how to generate:
<ServicesCertif iedMail="OFF" DeliveryConfirm ation="ON" ></Services>

I've tried several different combinations of methods and can't seem to
generate that string. Is it possible? If so, anyone know what I need to
do? I tried calling WriteString but it replaced the "<>" characters with
something else.

Thanks for reading,
Steve

Jun 10 '07 #6
Thank you for the reply, however I wish you had read the original post.

"**Disclaim er** The element I need to create might not be valid XML, but
it's not my fault, I'm following a required format for an integration
project."

This is not my format, I know it's ugly and I don't like having to use it
anymore that you would.
But I can't change the fact that the host application I'm integrating with
will be parsing this file and it cannot be changed.

Thanks again for the reply,
Steve
"clintonG" <no****@nowhere .comwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
From what I've observed, your XML is poorly formed and lacks consistent
structural style. You are using both elements and attributes which I
concede may be neccessary but in general just as often can and probably
should be restructured.

Secondly, the following use of an attribute as an element name is the
poorest type of form I have ever observed:

<ServicesCertif iedMail="OFF" DeliveryConfirm ation="ON" ></Services>

To solve the problem you are talking about -- in this news article --
simply refine your form:

<CertifiedMailS ervices serviceState="o ff" deliveryConfirm ation="on" />

Some time ago I wrote a similar RFI regarding style, form, and in
particular naming conventions was answered by Oleg Tkachenko an XML MVP
[1]. I found his reply useless as it obviates common sense.

The format I wrote above is what I have adopted ehich follows Tkachenko's
sage comments; the format being consistent with my use of C#. Further,
what I suggest one learn from this form of styling is the fact that the
XmlWriter will write attributes easily and as expected when the base form
is in fact well-formed and consistent of the ideal of that state of being
well-formed, i.e. when we clean up our sloppy form many of our problems go
away. So I'm trying to tell ya'...

Get some style boy ;-)

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee. com
URL http://clintongallagher.metromilwaukee.com/

[1] http://www.thescripts.com/forum/thread178080.html

"sklett" <s@s.comwrote in message
news:e0******** ******@TK2MSFTN GP03.phx.gbl...
>**Disclaimer ** The element I need to create might not be valid XML, but
it's not my fault, I'm following a required format for an integration
project.

I've got 99% of the XML created nicely using XmlWriter, there is one line
that I can't figure out how to generate:
<ServicesCerti fiedMail="OFF" DeliveryConfirm ation="ON" ></Services>

I've tried several different combinations of methods and can't seem to
generate that string. Is it possible? If so, anyone know what I need to
do? I tried calling WriteString but it replaced the "<>" characters with
something else.

Thanks for reading,
Steve


Jun 10 '07 #7
sklett <sk****@mddirec t.comwrote:
I somehow missed WriteRaw() last night, thanks for the suggestion! I just
tried it and it does write out the exact string I've given it, but with a
strange side effect: All subsequent calls to WriteElementStr ing are being
placed on the same line, one after another.
<snip>
Do you see anything there that would cause the writer to not write line
breaks after the call to WriteRaw()?
I expect it may be getting confused by trying to parse the contents of
your WriteRaw call to work out what's going on - I'm not sure, to be
honest.

*If* this is the case, an alternative (horrible though it is) would be
to flush the XmlWriter and manually write to the output stream before
continuing to use the XmlWriter.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 10 '07 #8
sklett <sk****@mddirec t.comwrote:
Thanks for the ideas and suggestions Jon.
I have been making noise to the api developers for this specific tool....
they just don't care.
Is this an internal API? If so, raise the issue with managers - it's
dangerous to let this kind of thing go unreported.

If it's an API from another company, I'd look for alternatives - if a
company doesn't care about following standards as widely used as XML,
who knows what other things they don't care about, such as reliability,
responsiveness to bug reports etc.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 10 '07 #9

"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************@m snews.microsoft .com...
sklett <sk****@mddirec t.comwrote:
>Thanks for the ideas and suggestions Jon.
I have been making noise to the api developers for this specific tool....
they just don't care.

Is this an internal API? If so, raise the issue with managers - it's
dangerous to let this kind of thing go unreported.
No, not internal, if it was I would fix ths crap myself ;)

>
If it's an API from another company, I'd look for alternatives - if a
company doesn't care about following standards as widely used as XML,
who knows what other things they don't care about, such as reliability,
responsiveness to bug reports etc.
The vendor I'm integrating with was not a first choice. I had originally
invested quite a bit of time directly with USPS's integration tools but
overlooked the apparent fact that you can't *actually* purchase postage from
USPS, you can verify addresses, requrest a label, etc. but there isn't a way
to get POSTAGE on the label from them. This blew me away, I coldn't
understand why, especially considering you CAN purchase postage on the web
site. Strange.

I'm integrating with a tool called "DAZzle" from Endicia. It's not perfect,
but does allow me to get something in place why we consider other options.
We don't have the budget to integrate with the larger, more robust solutions
that are out there.

Maybe you will appreciate this: :0)
1) agregate my transaction details from our CRM/ERP solution (which is VERY
powerful and open (NetSuite))
2) generate an xml file with the postage settings
3) launch a DAZzle process passing said xml file path on the command line
4) parse the result "output XML" file that DAZzle creates and store the
relevant data (tracking numbers, error codes, etc)

I have no control over the printer, the DAZzle process does that. Printer
out of paper or Printer offline? - I have now way to detect that.
It's not pretty, but like I said, it's what we can afford at this time.

If anyone knows of other options to create USPS postage labels WITH postage
I would LOVE to hear about it.

BTW, I don't mean to trash DAZzle, it's a fine little application but
integration was not it's intention and I suspect has been slipped in along
the way.

Thanks,
Steve
>
--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jun 10 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8039
by: Michael Malinak | last post by:
Since XmlWriter offers so many nice options for formatting, I thought it would be nice to read in via XmlReader, and write back out via XmlWriter. It might be overkill, but I'd also like to be able to check some values during that time also so I was going to be using XmlReader anyway. Unfortunately I don't see an easy way to stream it back out through XmlWriter without going node by node. Any suggestions? Is there an easier/faster way...
4
5559
by: Bob | last post by:
Hi Need to produce a Doc with no encoding info. Is there anyway of doing this? Thanks Bob i.e. <?xml version=\"1.0\" ?>
2
2280
by: Harry | last post by:
Hi, I am using XMLWriter to build xml and I need to build the element below. How do I do this? <Password format="encrypted">password</Password> Thanks
0
3616
by: Janusz Nykiel | last post by:
I've stumbled upon unexpected behavior of the .NET 2.0 System.Xml.XmlWriter class when using it to write data to a binary stream (System.IO.Stream). If the amount of data is less than a certain value (which varies depending on the data being written), characters not available in the encoding specified in the Encoding property of the XmlWritterSettings instance used to create the XmlWriter are being written to the resulting XML document as...
1
2961
by: MAF | last post by:
Is there a simple way to get the text, xml, from an xmlwriter. I have a XML writer that writes to a file, and I want another function to return the text that the xml writer is produced. Any suggestions?
2
19213
by: darrel | last post by:
I want to make my XML as such: <parentItem> <childItem attribute="myAttribute">myContent</childItem> </parentItem> I thought I could just do this: objXMLWriter.WriteElementString("childItem", "myContent") objXMLWriter.WriteAttributeString("attribute", "myAttribute")
9
6090
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a .net application and am using the xml writer class to create an xml file that opens as an excel file. I am trying to write out the following but am having difficulty. <Row> <Cell ss:StyleID="s87"> <ss:Data ss: Type = "String"> <Font html:Color="#FF0000">M90</Font> <Font>/Thu</Font> </ss:Data> </Cell>
2
4284
by: Hiren Mistry | last post by:
Hello, Experts. as i didnt got solution for "Creating XML from DTD" So finally i started creating DTD parser in C#.net........... Now i m facing problem while i create an xml element with name as "ectd:ectd" using xmlwriter........ but it gives an error or exception as ':' not valide character for xml element name
1
3108
by: JAM | last post by:
I'm trying to code some directory structure as my output / input file using XML. I would like to see formatiing with indentations. mimicking directory tree structure. Unfortunately the code such as this: using (XmlTextWriter xw = new XmlTextWriter("C:\\Temp\\test.xml", Encoding.UTF8)) { xw.Formatting = Formatting.Indented; xw.WriteStartDocument(); xw.WriteStartElement("FILTER", "");
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7721
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4366
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4615
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.