Solved

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

Posted on 2013-12-09
8
766 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
ID: 39707462
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
ID: 39707482
I tried this solution and I am still getting the XML parse error.
0
 
LVL 35

Expert Comment

by:mccarl
ID: 39707553
Is there any more information in the error message?
0
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 

Author Comment

by:starrj2012
ID: 39709005
The error message
That is what I am seeing
0
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 39710330
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 46

Expert Comment

by:Martin Liss
ID: 39758788
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

810 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