?
Solved

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

Posted on 2013-12-09
8
Medium Priority
?
854 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 36

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 36

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 36

Accepted Solution

by:
mccarl earned 2000 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 49

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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

764 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