Solved

Runtime Error whenever I try to run a macro to creat an XSD file

Posted on 2013-12-09
8
736 Views
Last Modified: 2014-01-06
I get a runtime error-XML Parse error when I run this script:

Sub Create_XSD()
   Dim StrMyXml As String, MyMap As XmlMap
   Dim StrMySchema As String
   StrMyXml = "<Order OrderId="" DisplayOrderId="" CreationDate="" cartCreationDate="" orderSubmissionDate="" orderSubmissionId="">"
   StrMyXml = StrMyXml & "<Prices>"
   StrMyXml = StrMyXml & "<Subtotal>999</Subtotal>"
   StrMyXml = StrMyXml & "<ShippingPrice>999</ShippingPrice>"
   StrMyXml = StrMyXml & "<MailingPrice>999</MailingPrice>"
   StrMyXml = StrMyXml & "<Tax>999</Tax>"
   StrMyXml = StrMyXml & "< Taxes Amount="">999</Taxes>"
   StrMyXml = StrMyXml & "<CouponDiscount CouponID="">999</CouponDiscount>"
   StrMyXml = StrMyXml & "<TotalPrice>999</TotalPrice>"
   StrMyXml = StrMyXml & "<Cost>999</Cost>"
   StrMyXml = StrMyXml & "</Prices>"
   StrMyXml = StrMyXml & "<Store Id="" externalId="">"
   StrMyXml = StrMyXml & "<Currency>Text</Currency>"
   StrMyXml = StrMyXml & "<PickupAddress>Text</PickupAddress>"
   StrMyXml = StrMyXml & "</Store>"
   StrMyXml = StrMyXml & "<User UserId="" externalId="">"
   StrMyXml = StrMyXml & "<FirstName>Text</FirstName>"
   StrMyXml = StrMyXml & "<LastName>Text</LastName>"
   StrMyXml = StrMyXml & "<Email>Text</Email>"
   StrMyXml = StrMyXml & "<Phone>999</Phone>"
   StrMyXml = StrMyXml & "<Mobile>999</Mobile>"
   StrMyXml = StrMyXml & "<Fax>999</Fax>"
   StrMyXml = StrMyXml & "<Company>Text</Company>"
   StrMyXml = StrMyXml & "<Department>Text</Department>"
   StrMyXml = StrMyXml & "<JobTitle>Text</JobTitle>"
   StrMyXml = StrMyXml & "</User>"
   StrMyXml = StrMyXml & "<BillingAddress>"
   StrMyXml = StrMyXml & "<Name>Text</Name>"
   StrMyXml = StrMyXml & "<Company>Text</Company>"
   StrMyXml = StrMyXml & "<Address1>Text</Address1>"
   StrMyXml = StrMyXml & "<Address2>Text</Address2>"
   StrMyXml = StrMyXml & "<City>Text</City>"
   StrMyXml = StrMyXml & "<State>Text</State>"
   StrMyXml = StrMyXml & "<ZipCode>999</ZipCode>"
   StrMyXml = StrMyXml & "<Country>Text</Country>"
   StrMyXml = StrMyXml & "<Phone>999</Phone>"
   StrMyXml = StrMyXml & "<Fax>999</Fax>"
   StrMyXml = StrMyXml & "<AddressReference>Text</AddressReference>"
   StrMyXml = StrMyXml & "</BillingAddress>"
   StrMyXml = StrMyXml & "<Deliveries>"
   StrMyXml = StrMyXml & "<Delivery>"
   StrMyXml = StrMyXml & "<Method>Text</Method>"
   StrMyXml = StrMyXml & "<DeliveryProvider id="">Text</DeliveryProvider>"
   StrMyXml = StrMyXml & "<DeliveryService id="">Text</DeliveryService>"
   StrMyXml = StrMyXml & "<DeliveryPrice>999</DeliveryPrice>"
   StrMyXml = StrMyXml & "<ShippingTax Percentage="">999</ShippingTax>"
   StrMyXml = StrMyXml & "<ShippingAddress>"
   StrMyXml = StrMyXml & "<Name>Text</Name>"
   StrMyXml = StrMyXml & "<Company>Text</Company>"
   StrMyXml = StrMyXml & "<Address1>Text</Address1>"
   StrMyXml = StrMyXml & "<Address2>Text</Address2>"
   StrMyXml = StrMyXml & "<City>Text</City>"
   StrMyXml = StrMyXml & "<State>Text</State>"
   StrMyXml = StrMyXml & "<ZipCode>999</ZipCode>"
   StrMyXml = StrMyXml & "<Country>Text</Country>"
   StrMyXml = StrMyXml & "<Phone>999</Phone>"
   StrMyXml = StrMyXml & "<Fax>999</Fax>"
   StrMyXml = StrMyXml & "<AddressReference>Text</AddressReference>"
   StrMyXml = StrMyXml & "</ShippingAddress>"
   StrMyXml = StrMyXml & "<DeliveryItems>"
   StrMyXml = StrMyXml & "<DeliveryItem id="">"
   StrMyXml = StrMyXml & "<OrderProductId>999</OrderProductId>"
   StrMyXml = StrMyXml & "<NumberOfUnits>999</NumberOfUnits>"
   StrMyXml = StrMyXml & "</DeliveryItem>"
   StrMyXml = StrMyXml & "<DeliverItem></DeliveryItem>"
   StrMyXml = StrMyXml & "</DeliveryItems>"
   StrMyXml = StrMyXml & "</Delivery>"
   StrMyXml = StrMyXml & "</Deliveries>"
   StrMyXml = StrMyXml & "<OrderProducts>"
   StrMyXml = StrMyXml & "<OrderProduct id="" creationDate="">"
   StrMyXml = StrMyXml & "<Quantities>"
   StrMyXml = StrMyXml & "<NumberOfRecipients>999</NumberOfRecipients>"
   StrMyXml = StrMyXml & "<NumberOfCopies>999</NumberOfCopies>"
   StrMyXml = StrMyXml & "<TotalUnits>999</TotalUnits>"
   StrMyXml = StrMyXml & "</Quantities>"
   StrMyXml = StrMyXml & "<Prices>"
   StrMyXml = StrMyXml & "<FixedPrice>999</FixedPrice>"
   StrMyXml = StrMyXml & "<PricePerRecipient>999</PricePerRecipient>"
   StrMyXml = StrMyXml & "<PricePerUnit>999</PricePerUnit>"
   StrMyXml = StrMyXml & "<Subtotal>999</Subtotal>"
   StrMyXml = StrMyXml & "<MailingPrice>999</MailingPrice>"
   StrMyXml = StrMyXml & "<TotalPrice>999</TotalPrice>"
   StrMyXml = StrMyXml & "<Cost>999</Cost>"
   StrMyXml = StrMyXml & "</Prices>"
   StrMyXml = StrMyXml & "<Delivery>Text</Delivery>"
   StrMyXml = StrMyXml & "<ProductUnit id="" itemsAmount="">Text</ProductUnit>"
   StrMyXml = StrMyXml & "<Product id="" externalId="">"
   StrMyXml = StrMyXml & "<Name>Text</Name>"
   StrMyXml = StrMyXml & "<CatalogNumber>999</CatalogNumber>"
   StrMyXml = StrMyXml & "<Type>Text</Type>"
   StrMyXml = StrMyXml & "<Downloadable>Text</Downloadable>"
   StrMyXml = StrMyXml & "<Manufacturer externalId="">999</Manufacturer>"
   StrMyXml = StrMyXml & "</Product>"
   StrMyXml = StrMyXml & "<DialValues>"
   StrMyXml = StrMyXml & "<DialValue>"
   StrMyXml = StrMyXml & "<Dial id="">"
   StrMyXml = StrMyXml & "<PlanName>Text</PlanName>"
   StrMyXml = StrMyXml & "<DisplayName>Text</DisplayName>"
   StrMyXml = StrMyXml & "</Dial>"
   StrMyXml = StrMyXml & "<Value>Text</Value>"
   StrMyXml = StrMyXml & "</DialValue>"
   StrMyXml = StrMyXml & "<DialValue></DialValue>"
   StrMyXml = StrMyXml & "</DialValues>"
   StrMyXml = StrMyXml & "<PropertyValues>"
   StrMyXml = StrMyXml & "<PropertyValue>"
   StrMyXml = StrMyXml & "<Property id="" externalId="">"
   StrMyXml = StrMyXml & "<DisplayName>Text</DisplayName>"
   StrMyXml = StrMyXml & "</Property>"
   StrMyXml = StrMyXml & "<Value>Text</Value>"
   StrMyXml = StrMyXml & "</PropertyValue>"
   StrMyXml = StrMyXml & "<PropertyValue></PropertyValue>"
   StrMyXml = StrMyXml & "</PropertyValues>"
   StrMyXml = StrMyXml & "</OrderProduct>"
   StrMyXml = StrMyXml & "</OrderProducts>"
   StrMyXml = StrMyXml & "<Clearing type="">"
   StrMyXml = StrMyXml & "<Value>"
   StrMyXml = StrMyXml & "<NoClearing>Text</NoClearing>"
   StrMyXml = StrMyXml & "</Value>"
   StrMyXml = StrMyXml & "</Clearing>"
   StrMyXml = StrMyXml & "</Order>"

   ' Turn off async loading.
   Application.DisplayAlerts = False
   ' Add the string to the XmlMaps collection.
   Set MyMap = ThisWorkbook.XmlMaps.Add(StrMyXml)
   Application.DisplayAlerts = True

   ' Create an empty file and output the schema.
   StrMySchema = ThisWorkbook.XmlMaps(1).Schemas(1).XML
   Open "C:\MySchema.xsd" For Output As #1
   Print #1, StrMySchema
   Close #1
End Sub

Open in new window

What am I missing?
0
Comment
Question by:starrj2012
  • 3
  • 2
8 Comments
 
LVL 35

Expert Comment

by:mccarl
Comment Utility
The double quotes, ie. ", that are actually part of the xml need to be escaped so that they are NOT counted as the end of the string by VB. To escape double quotes, you need to double them, so your script should be something like this...
Sub Create_XSD()
   Dim StrMyXml As String, MyMap As XmlMap
   Dim StrMySchema As String
   StrMyXml = "<Order OrderId="""" DisplayOrderId="""" CreationDate="""" cartCreationDate="""" orderSubmissionDate="""" orderSubmissionId="""">"
   StrMyXml = StrMyXml & "<Prices>"
   StrMyXml = StrMyXml & "<Subtotal>999</Subtotal>"
   StrMyXml = StrMyXml & "<ShippingPrice>999</ShippingPrice>"
   StrMyXml = StrMyXml & "<MailingPrice>999</MailingPrice>"
   StrMyXml = StrMyXml & "<Tax>999</Tax>"
   StrMyXml = StrMyXml & "< Taxes Amount="""">999</Taxes>"
   StrMyXml = StrMyXml & "<CouponDiscount CouponID="""">999</CouponDiscount>"
   StrMyXml = StrMyXml & "<TotalPrice>999</TotalPrice>"
   StrMyXml = StrMyXml & "<Cost>999</Cost>"
   StrMyXml = StrMyXml & "</Prices>"
   StrMyXml = StrMyXml & "<Store Id="""" externalId="""">"
   StrMyXml = StrMyXml & "<Currency>Text</Currency>"
   StrMyXml = StrMyXml & "<PickupAddress>Text</PickupAddress>"
   StrMyXml = StrMyXml & "</Store>"
   StrMyXml = StrMyXml & "<User UserId="""" externalId="""">"
   StrMyXml = StrMyXml & "<FirstName>Text</FirstName>"
   StrMyXml = StrMyXml & "<LastName>Text</LastName>"
   StrMyXml = StrMyXml & "<Email>Text</Email>"
   StrMyXml = StrMyXml & "<Phone>999</Phone>"
   StrMyXml = StrMyXml & "<Mobile>999</Mobile>"
   StrMyXml = StrMyXml & "<Fax>999</Fax>"
   StrMyXml = StrMyXml & "<Company>Text</Company>"
   StrMyXml = StrMyXml & "<Department>Text</Department>"
   StrMyXml = StrMyXml & "<JobTitle>Text</JobTitle>"
   StrMyXml = StrMyXml & "</User>"
   StrMyXml = StrMyXml & "<BillingAddress>"
   StrMyXml = StrMyXml & "<Name>Text</Name>"
   StrMyXml = StrMyXml & "<Company>Text</Company>"
   StrMyXml = StrMyXml & "<Address1>Text</Address1>"
   StrMyXml = StrMyXml & "<Address2>Text</Address2>"
   StrMyXml = StrMyXml & "<City>Text</City>"
   StrMyXml = StrMyXml & "<State>Text</State>"
   StrMyXml = StrMyXml & "<ZipCode>999</ZipCode>"
   StrMyXml = StrMyXml & "<Country>Text</Country>"
   StrMyXml = StrMyXml & "<Phone>999</Phone>"
   StrMyXml = StrMyXml & "<Fax>999</Fax>"
   StrMyXml = StrMyXml & "<AddressReference>Text</AddressReference>"
   StrMyXml = StrMyXml & "</BillingAddress>"
   StrMyXml = StrMyXml & "<Deliveries>"
   StrMyXml = StrMyXml & "<Delivery>"
   StrMyXml = StrMyXml & "<Method>Text</Method>"
   StrMyXml = StrMyXml & "<DeliveryProvider id="""">Text</DeliveryProvider>"
   StrMyXml = StrMyXml & "<DeliveryService id="""">Text</DeliveryService>"
   StrMyXml = StrMyXml & "<DeliveryPrice>999</DeliveryPrice>"
   StrMyXml = StrMyXml & "<ShippingTax Percentage="""">999</ShippingTax>"
   StrMyXml = StrMyXml & "<ShippingAddress>"
   StrMyXml = StrMyXml & "<Name>Text</Name>"
   StrMyXml = StrMyXml & "<Company>Text</Company>"
   StrMyXml = StrMyXml & "<Address1>Text</Address1>"
   StrMyXml = StrMyXml & "<Address2>Text</Address2>"
   StrMyXml = StrMyXml & "<City>Text</City>"
   StrMyXml = StrMyXml & "<State>Text</State>"
   StrMyXml = StrMyXml & "<ZipCode>999</ZipCode>"
   StrMyXml = StrMyXml & "<Country>Text</Country>"
   StrMyXml = StrMyXml & "<Phone>999</Phone>"
   StrMyXml = StrMyXml & "<Fax>999</Fax>"
   StrMyXml = StrMyXml & "<AddressReference>Text</AddressReference>"
   StrMyXml = StrMyXml & "</ShippingAddress>"
   StrMyXml = StrMyXml & "<DeliveryItems>"
   StrMyXml = StrMyXml & "<DeliveryItem id="""">"
   StrMyXml = StrMyXml & "<OrderProductId>999</OrderProductId>"
   StrMyXml = StrMyXml & "<NumberOfUnits>999</NumberOfUnits>"
   StrMyXml = StrMyXml & "</DeliveryItem>"
   StrMyXml = StrMyXml & "<DeliverItem></DeliveryItem>"
   StrMyXml = StrMyXml & "</DeliveryItems>"
   StrMyXml = StrMyXml & "</Delivery>"
   StrMyXml = StrMyXml & "</Deliveries>"
   StrMyXml = StrMyXml & "<OrderProducts>"
   StrMyXml = StrMyXml & "<OrderProduct id="""" creationDate="""">"
   StrMyXml = StrMyXml & "<Quantities>"
   StrMyXml = StrMyXml & "<NumberOfRecipients>999</NumberOfRecipients>"
   StrMyXml = StrMyXml & "<NumberOfCopies>999</NumberOfCopies>"
   StrMyXml = StrMyXml & "<TotalUnits>999</TotalUnits>"
   StrMyXml = StrMyXml & "</Quantities>"
   StrMyXml = StrMyXml & "<Prices>"
   StrMyXml = StrMyXml & "<FixedPrice>999</FixedPrice>"
   StrMyXml = StrMyXml & "<PricePerRecipient>999</PricePerRecipient>"
   StrMyXml = StrMyXml & "<PricePerUnit>999</PricePerUnit>"
   StrMyXml = StrMyXml & "<Subtotal>999</Subtotal>"
   StrMyXml = StrMyXml & "<MailingPrice>999</MailingPrice>"
   StrMyXml = StrMyXml & "<TotalPrice>999</TotalPrice>"
   StrMyXml = StrMyXml & "<Cost>999</Cost>"
   StrMyXml = StrMyXml & "</Prices>"
   StrMyXml = StrMyXml & "<Delivery>Text</Delivery>"
   StrMyXml = StrMyXml & "<ProductUnit id="""" itemsAmount="""">Text</ProductUnit>"
   StrMyXml = StrMyXml & "<Product id="""" externalId="""">"
   StrMyXml = StrMyXml & "<Name>Text</Name>"
   StrMyXml = StrMyXml & "<CatalogNumber>999</CatalogNumber>"
   StrMyXml = StrMyXml & "<Type>Text</Type>"
   StrMyXml = StrMyXml & "<Downloadable>Text</Downloadable>"
   StrMyXml = StrMyXml & "<Manufacturer externalId="""">999</Manufacturer>"
   StrMyXml = StrMyXml & "</Product>"
   StrMyXml = StrMyXml & "<DialValues>"
   StrMyXml = StrMyXml & "<DialValue>"
   StrMyXml = StrMyXml & "<Dial id="""">"
   StrMyXml = StrMyXml & "<PlanName>Text</PlanName>"
   StrMyXml = StrMyXml & "<DisplayName>Text</DisplayName>"
   StrMyXml = StrMyXml & "</Dial>"
   StrMyXml = StrMyXml & "<Value>Text</Value>"
   StrMyXml = StrMyXml & "</DialValue>"
   StrMyXml = StrMyXml & "<DialValue></DialValue>"
   StrMyXml = StrMyXml & "</DialValues>"
   StrMyXml = StrMyXml & "<PropertyValues>"
   StrMyXml = StrMyXml & "<PropertyValue>"
   StrMyXml = StrMyXml & "<Property id="""" externalId="""">"
   StrMyXml = StrMyXml & "<DisplayName>Text</DisplayName>"
   StrMyXml = StrMyXml & "</Property>"
   StrMyXml = StrMyXml & "<Value>Text</Value>"
   StrMyXml = StrMyXml & "</PropertyValue>"
   StrMyXml = StrMyXml & "<PropertyValue></PropertyValue>"
   StrMyXml = StrMyXml & "</PropertyValues>"
   StrMyXml = StrMyXml & "</OrderProduct>"
   StrMyXml = StrMyXml & "</OrderProducts>"
   StrMyXml = StrMyXml & "<Clearing type="""">"
   StrMyXml = StrMyXml & "<Value>"
   StrMyXml = StrMyXml & "<NoClearing>Text</NoClearing>"
   StrMyXml = StrMyXml & "</Value>"
   StrMyXml = StrMyXml & "</Clearing>"
   StrMyXml = StrMyXml & "</Order>"

   ' Turn off async loading.
   Application.DisplayAlerts = False
   ' Add the string to the XmlMaps collection.
   Set MyMap = ThisWorkbook.XmlMaps.Add(StrMyXml)
   Application.DisplayAlerts = True

   ' Create an empty file and output the schema.
   StrMySchema = ThisWorkbook.XmlMaps(1).Schemas(1).XML
   Open "C:\MySchema.xsd" For Output As #1
   Print #1, StrMySchema
   Close #1
End Sub

Open in new window

Hopefully I got them all, but you should have the right idea now, so that you can sort out any that I might have missed!
0
 

Author Comment

by:starrj2012
Comment Utility
I tried this solution and I am still getting the XML parse error.
0
 
LVL 35

Expert Comment

by:mccarl
Comment Utility
Is there any more information in the error message?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:starrj2012
Comment Utility
The error message
That is what I am seeing
0
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
Comment Utility
That is what I am seeing
Ahh, it's not much is it!  ;)

Anyway, I chucked your code into a macro and was able to find a couple of more errors...

On line 10, (on your original or my updated version) you have a stray "whitespace" character after the opening < and before the element name "Taxes", you need to get rid of that.

On line 68, you have <DeliverItem> as the open tag but </DeliveryItem> as the closing tag, so they don't match up.



After fixing those, the script ran without error.
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now