|
-
Apr 23rd, 2003, 11:59 AM
#1
Thread Starter
I wonder how many charact
XmlTextWriter class question
Using the XmlTextWriter class, how would I write out the line bolded below with the results shown below:
Code:
<?xml version="1.0" ?>
<?qbxml version="2.0"?>
<QBXML>
<QBXMLMsgsRq onError = "stopOnError">
<CustomerAddRq requestID = "1">
<CustomerAdd>
<Name>Some Guy</Name>
</CustomerAdd>
</CustomerAddRq>
</QBXMLMsgsRq>
</QBXML>
I am trying to start an element but also include addt'l information...
namely, onError = "stopOnError"
If I use
VB Code:
myXml.WriteStartElement("QBXMLMsgsRq onError='stopOnError'", Nothing)
I get this where the ending tag also includes the extra info)
Code:
<?xml version='1.0' ?>
<QBXML>
<QBXMLMsgsRq onError='stopOnError'>
<CustomerAddRq requestID='1'>
<CustomerAdd>
<Name>Karl</Name>
</CustomerAdd>
</CustomerAddRq requestID='1'>
</QBXMLMsgsRq onError='stopOnError'>
</QBXML>ML>
Now obviously I know why it makes the end tag the same...but I can't figure out how to get around that...
I want the bolded line above to just read </QBXMLMsgsRq>. In case you are wondering, this is xml structured request for adding a customer to Intuit's Quickbooks.
Last edited by nemaroller; Apr 23rd, 2003 at 12:08 PM.
-
Apr 23rd, 2003, 12:06 PM
#2
Try WriteStartAttribute for adding the attribute.
-
Apr 23rd, 2003, 12:12 PM
#3
Thread Starter
I wonder how many charact
thanks Cander.... writes as expected now...
-
Apr 23rd, 2003, 12:18 PM
#4
You should check out the XMLDocument class, if you haven't already, with somethings it can be much easier to use.
-
Apr 23rd, 2003, 12:20 PM
#5
Thread Starter
I wonder how many charact
While I got your attention:
VB Code:
myXml.WriteRaw("<?qbxml version = '2.0' ?>")
How do I write the 2.0 inside a pair of double quotes?
-
Apr 23rd, 2003, 12:22 PM
#6
try
myXml.WriteRaw("<?qbxml version = ""2.0"" ?>")
assuming it still does it like VB6 does.
-
Apr 23rd, 2003, 12:31 PM
#7
Thread Starter
I wonder how many charact
yea... well it works .WriteRaw, (loses the CRLF though),
but for
myXml.WriteStartAttribute("onError = ""stopOnError"", Nothing)
it fails to even compile....
-
Apr 23rd, 2003, 12:43 PM
#8
Thread Starter
I wonder how many charact
I'm able to use the double quotes using this:
Code:
myXml.WriteStartAttribute("onError= " & c & "stopOnError" & c, Nothing)
where c is defined a char type of value 34 (double quotes)
But now have a problem related to my earlier question, see output below.
Here's my code:
Code:
Dim myXml As XmlTextWriter = New XmlTextWriter(mySendStream, System.Text.Encoding.UTF8)
Dim c As Char
c = Chr(34)
myXml.Formatting = System.Xml.Formatting.Indented
myXml.WriteRaw("<?xml version = ""1.0"" ?>")
myXml.WriteRaw("<?qbxml version = ""2.0"" ?>")
myXml.WriteStartElement("QBXML", Nothing)
myXml.WriteStartElement("QBXMLMsgsRq")
myXml.WriteStartAttribute("onError= " & c & "stopOnError" & c, Nothing)
myXml.WriteEndAttribute()
myXml.WriteStartElement("CustomerAddRq")
myXml.WriteStartAttribute("requestID = " & c & "1" & c, Nothing)
myXml.WriteEndAttribute()
myXml.WriteStartElement("CustomerAdd")
myXml.WriteElementString("Name", Nothing, "Karl")
'close tags
myXml.WriteEndElement()
myXml.WriteEndElement()
myXml.WriteEndElement()
myXml.WriteEndElement()
myXml.Flush()
myXml.Close()
Here's the output (problems in bold):
VB Code:
<?xml version = "1.0" ?><?qbxml version = "2.0" ?>
<QBXML>
<QBXMLMsgsRq onError= "stopOnError"[color=red]=""[/color]> 'the writeStartAttribute problem
<CustomerAddRq requestID = "1"[color=red]=""[/color]>
<CustomerAdd>
<Name>Karl</Name>
</CustomerAdd>
</CustomerAddRq>
</QBXMLMsgsRq>
</QBXML>
Last edited by nemaroller; Apr 23rd, 2003 at 12:48 PM.
-
Apr 23rd, 2003, 01:45 PM
#9
Its because you didn't give it a value properly, try using the WriteAttributeString method instead:
VB Code:
myXml.WriteRaw("<?xml version = ""1.0"" ?>")
myXml.WriteRaw("<?qbxml version = ""2.0"" ?>")
myXml.WriteStartElement("QBXML", Nothing)
myXml.WriteStartElement("QBXMLMsgsRq")
myXml.WriteAttributeString("onError", "stopOnError")
myXml.WriteStartElement("CustomerAddRq")
myXml.WriteAttributeString("requestID", "1")
myXml.WriteStartElement("CustomerAdd")
myXml.WriteElementString("Name", Nothing, "Karl")
-
Apr 23rd, 2003, 02:00 PM
#10
You can also use WriteProcessingInstruction to write the top part out and have it on two lines.
VB Code:
myXml.WriteProcessingInstruction("xml", "version=""1.0""")
myXml.WriteProcessingInstruction("qbxml", "version=""2.0""")
-
Apr 23rd, 2003, 06:22 PM
#11
Thread Starter
I wonder how many charact
Edneeis.... thank you very much for your response... it 's all kosher now...
-
Apr 24th, 2003, 12:32 PM
#12
Thread Starter
I wonder how many charact
Funny thing is... the only way I got these XML files to work was to change the encoding from UTF8 to ASCII. I suppose that was a limitation of Intuit's Quickbooks XML parser ...
VB Code:
Dim mySendStream As IO.FileStream = New FileStream("C:\mxml1.xml", FileMode.Create)
Dim myXml As XmlTextWriter = New XmlTextWriter(mySendStream, [b]System.Text.Encoding.ASCII[/b])
myXml.Formatting = System.Xml.Formatting.Indented
'write xml version and encoding
myXml.WriteStartDocument()
'write QuickBook's QBXML version
myXml.WriteProcessingInstruction("qbxml", "version=""1.1""")
'write data
myXml.WriteStartElement("QBXML", Nothing)
myXml.WriteStartElement("QBXMLMsgsRq")
myXml.WriteAttributeString("onError", "stopOnError")
myXml.WriteStartElement("CustomerAddRq")
myXml.WriteAttributeString("requestID", "1")
myXml.WriteStartElement("CustomerAdd")
myXml.WriteElementString("Name", Nothing, "Dirk Diggler")
'close tags
myXml.WriteEndDocument()
myXml.Flush()
myXml.Close()
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
|