Solved

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

Posted on 2013-12-09
8
793 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 47

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protecting vb6 & .Net code Obfuscation 18 183
Not seen Link button 5 73
Create Files based on Cell Values in a Range in Excel 12 43
Link failure 16 66
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
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.
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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