Solved

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

Posted on 2013-12-09
8
812 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 

Author Comment

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

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

688 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